Skip to content

test: improve test error message logs #23694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Aug 4, 2022

No description provided.

@@ -96,39 +96,47 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
_processes.push(childProcess);

// Create the error here so the stack shows who called this function.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this wasn't actually done before? Creating the error with the stack trace at this point is the primary change. Otherwise the stack trace is always just the child_process exit/error stack which is useless.

// Return log info about the current process status
function envDump() {
return [
`ENV:${JSON.stringify(spawnOptions.env, null, 2)}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also changed but is a bit hard to see. It now outputs the env of the process being spawned, not the parent process - spawnOptions.env isntead of process.env. I think that is far more useful and probably the original intention?

@@ -96,39 +96,47 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
_processes.push(childProcess);

// Create the error here so the stack shows who called this function.
let error: Error;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the below do the same?

Suggested change
let error: Error;
const error = new Error();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're correct. I always thought the stack was where the error was thrown, but it's actually just where it was constructed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. Can also change the catch to which is more readable.

  }).catch((err) => {
    // Create the error here so the stack shows who called this function.
    return Promise.reject(new Error(err));
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do the new Error in the catch callback doesn't that mean the stack trace will be just the callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

@jbedard jbedard force-pushed the e2e-error-stacks branch 2 times, most recently from f1cdb91 to e5c5c4e Compare August 5, 2022 18:26
@jbedard jbedard requested a review from alan-agius4 August 5, 2022 18:29
reject(
`Process output didn't match - "${cmd} ${args.join(' ')}": '${
options.waitForMatch
}': ${code}...\n\n${envDump()}\n`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note both the code (formerly error) and the envDump() were not here previously.

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Aug 8, 2022
@clydin clydin merged commit 9171543 into angular:main Aug 9, 2022
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants