Skip to content

fix: include cause of parsing errors in action output logs - #431

Merged
zimeg merged 6 commits into
slackapi:mainfrom
zimeg:main
May 6, 2025
Merged

zimeg merged 6 commits into
slackapi:mainfrom
zimeg:main

Conversation

@zimeg

@zimeg zimeg commented Apr 22, 2025

Copy link
Copy Markdown
Member

Summary

This PR includes the cause of parsing errors in action output logs to fix #359.

Requirements

@codecov

codecov Bot commented Apr 22, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.85%. Comparing base (c7dafcf) to head (b0c83a8).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #431   +/-   ##
=======================================
  Coverage   99.85%   99.85%           
=======================================
  Files           7        7           
  Lines         703      709    +6     
=======================================
+ Hits          702      708    +6     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zimeg

zimeg commented Apr 22, 2025

Copy link
Copy Markdown
Member Author

📝 Example of invalid YAML:
https://github.com/zimeg/slack-sandbox/actions/runs/14603929191/job/40968479290#step:2:12

YAMLException: bad indentation of a mapping entry (2:19)

 1 | channel: ***,
 2 | text: "greetings!",
-----------------------^

📝 Example of invalid JSON:
https://github.com/zimeg/slack-sandbox/actions/runs/14603970704/job/40968613223#step:2:13

SyntaxError: Expected ',' or '}' after property value in JSON at position 52
    at JSON.parse (<anonymous>)

📝 Example of invalid attributes:
https://github.com/zimeg/slack-sandbox/actions/runs/14604005898/job/40968725587#step:2:14

Error: missing required field: channel
Error: SlackError: An API error occurred: invalid_arguments
Error: An API error occurred: invalid_arguments

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

📣 A note on some strange patterns in these changes for the kind reviewers!

Comment thread src/index.js
Comment on lines +13 to +21
/** @type {import('./errors.js').Cause} */
const causes = /** @type {any} */ (error.cause);
if (causes?.values) {
for (const cause of causes.values) {
core.info(`${cause.stack}`);
}
} else {
core.info(`${error.stack}`);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🔗 The error cause values is valid data but typescript treats causes as "unknown" so this worksaround that.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#providing_structured_data_as_the_error_cause

@zimeg
zimeg marked this pull request as ready for review April 22, 2025 20:31

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ LGTM! Huge improvement to the error messages. Hopefully this helps folks debug issues more easily!

Comment thread src/index.js
*/
try {
send(core);
await send(core);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🎉

@zimeg

zimeg commented May 1, 2025

Copy link
Copy Markdown
Member Author

📝 Example of invalid YAML file:
https://github.com/zimeg/slack-sandbox/actions/runs/14770123380/job/41468715105#step:3:10

YAMLException: expected a single document in the stream, but found more
    at Object.load$1 [as load] (file:///home/runner/work/_actions/zimeg/slack-github-action/v2.0.1-rc.5/node_modules/js-yaml/dist/js-yaml.mjs:2812:1)

📝 Example of invalid JSON file:
https://github.com/zimeg/slack-sandbox/actions/runs/14770064204/job/41468560233#step:3:11

SyntaxError: Bad control character in string literal in JSON at position 21
    at JSON.parse (<anonymous>)

📝 Example of missing file:
https://github.com/zimeg/slack-sandbox/actions/runs/14770087484/job/41468622000#step:3:12

Error: ENOENT: no such file or directory, open '/home/runner/work/slack-sandbox/slack-sandbox/oop.yaml'
    at Object.readFileSync (node:fs:449:20)

@zimeg

zimeg commented May 1, 2025

Copy link
Copy Markdown
Member Author

📝 Example of invalid arguments from a payload file too:
https://github.com/zimeg/slack-sandbox/actions/runs/14770107368/job/41468674575#step:3:14

Error: missing required field: channel
Error: SlackError: An API error occurred: invalid_arguments
Error: An API error occurred: invalid_arguments

@zimeg

zimeg commented May 6, 2025

Copy link
Copy Markdown
Member Author

@mwbrooks @hello-ashleyintech 🫡

With both unexpected text and file inputs returning perhaps more meaningful errors, let's merge this! I might imagine follow up that continues to improve upon these outputs, perhaps logging the actual inputs, but for now this I hope is helpful.

After this merges, I will test a release candidate a few times for confidence. Then I look forward to a new release 🚀

@zimeg
zimeg merged commit ab965e5 into slackapi:main May 6, 2025
@zimeg zimeg modified the milestones: 2.0.1, 2.1 May 6, 2025

This branch was previously deployed

1 inactive deployment
staging — b0c83a80 Deployed May 6, 2025 by zimeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error reporting when action fail to parse correctly the payload

2 participants