Skip to content
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

Bad error handling #612

Closed
josephjclark opened this issue Feb 23, 2024 · 4 comments
Closed

Bad error handling #612

josephjclark opened this issue Feb 23, 2024 · 4 comments
Assignees

Comments

@josephjclark
Copy link
Collaborator

josephjclark commented Feb 23, 2024

We've encountered some cases of bad error handling.

I think the problem is that the logger is doing a bad job of console.logging an error object.

We can see this in mailgun.

@github-project-automation github-project-automation bot moved this to New Issues in v2 Feb 23, 2024
@josephjclark josephjclark moved this from New Issues to In review in v2 Feb 23, 2024
@josephjclark josephjclark self-assigned this Feb 23, 2024
@mtuchi
Copy link
Contributor

mtuchi commented Feb 23, 2024

send({
  from: 'MG User <[email protected]>',
  to: ['[email protected]'],
  subject: 'Hello',
  html: '<h1>Hello World</h1>',
  //   attachment: {
  //     url: 'https://www.openfn.org/_astro/cambodia-kids.75bc9a92_Z25RlBy.webp',
  //     filename: 'cambodia.webp',
  //   },
});

{
    "configuration": {
        "domain": "sandbox3c212ac1038f4dd7a2765782f3cf1980.mailgun.org",
        "apiKey": "123"
    }
}
openfn tmp/mail.js -ma mailgun -s tmp/state.json -o tmp/output.json -l debug
[CLI] ♦ Versions:
         ▸ node.js                     18.17.1
         ▸ cli                         0.4.13
         ▸ runtime                     0.2.4
         ▸ compiler                    0.0.38
         ▸ @openfn/language-mailgun    latest
[CLI] ✔ Loading adaptors from monorepo at /Users/openfn/Workspace/adaptors
[CLI] ℹ Mapped adaptor @openfn/language-mailgun to monorepo: /Users/openfn/Workspace/adaptors/packages/mailgun
[CLI] ❯ Loading job from tmp/mail.js
[CLI] ❯ Loading state...
[CLI] ✔ Loaded state from tmp/state.json
[CLI] ❯ state: {
  "configuration": {
    "domain": "****",
    "apiKey": "****"
  }
}
[CLI] ❯ Compiling...
[CLI] ❯ Attempting to preload types for @openfn/language-mailgun
[CLI] ❯ Resolved @openfn/language-mailgun to path: /Users/openfn/Workspace/adaptors/packages/mailgun
[CLI] ❯ Starting compilation from string
[CLI] ℹ Added import statement for @openfn/language-mailgun
[CLI] ℹ Added export * statement for @openfn/language-mailgun
[CLI] ❯ Compiled source:
[CLI] ❯ import { send } from "@openfn/language-mailgun";
export * from "@openfn/language-mailgun";

export default [send({
  from: 'MG User <[email protected]>',
  to: ['[email protected]'],
  subject: 'Hello',
  html: '<h1>Hello World</h1>',
  //   attachment: {
  //     url: 'https://www.openfn.org/_astro/cambodia-kids.75bc9a92_Z25RlBy.webp',
  //     filename: 'cambodia.webp',
  //   },
})];

[CLI] ✔ Compiled from tmp/mail.js
[R/T] ❯ Generated execution plan for incoming expression
[R/T] ❯ {
  "jobs": [
    {
      "expression": "import { send } from \"@openfn/language-mailgun\";\nexport * from \"@openfn/language-mailgun\";\n\nexport default [send({\n  from: 'MG User <[email protected]>',\n  to: ['[email protected]'],\n  subject: 'Hello',\n  html: '<h1>Hello World</h1>',\n  //   attachment: {\n  //     url: 'https://www.openfn.org/_astro/cambodia-kids.75bc9a92_Z25RlBy.webp',\n  //     filename: 'cambodia.webp',\n  //   },\n})];\n"
    }
  ]
}
[R/T] ♦ Starting job job-1
[R/T] ❯ Intialising pipeline
[R/T] ❯ Timeout set to 300000ms
[R/T] ❯ [linker] loading module @openfn/language-mailgun
[R/T] ❯ [linker] Loading module @openfn/language-mailgun from /Users/openfn/Workspace/adaptors/packages/mailgun/dist/index.cjs
[R/T] ℹ Resolved adaptor @openfn/language-mailgun to version 0.4.3
[R/T] ❯ Executing expression (1 operations)
[R/T] ❯ Starting operation 1
Sending mail:
[R/T] ❯ Removed configuration from final state
[R/T] ✘ Failed job job-1 after 2.131s
[R/T] ✘ JobError: Unauthorized
[R/T] ❯ [JobError] Unauthorized
[R/T] ✘ Check state.errors.job-1 for details.
[CLI] ❯ Writing output to tmp/output.json
[CLI] ✔ State written to tmp/output.json
[CLI] ⚠ Errors reported in 1 jobs
[CLI] ✔ Finished in 2.215s

@josephjclark
Copy link
Collaborator Author

josephjclark commented May 16, 2024

Another case from [email protected]

If you don't have valid credentials, the error is rather terse:

JobError: Request failed with status code 401

I mean it's OK but I suspect there's more details coming down from commcare and surely we can do more with this? The actual message is encoded in the body, and the request comes from axios.

You should just be able to run this:

submitXls(
  [
    { name: 'Elizabeth', feeling_sick: 'No' },
  ]
);

With this credential:

{
  "configuration": {
    "hostUrl": "https://www.commcarehq.org",
    "username": "[email protected]",
    "applicationName": "test-20190880",
    "appId": "68df1b1d2a1f4aafbeee4a2e27ca1089",
  }
}

And you'll get the 401 back.

@josephjclark
Copy link
Collaborator Author

Commcare again - see OpenFn/adaptors#591

On point 5, the adaptor threw some kind of error. Fine. But it would be nice to see the sack trace in this case to understand WHERE the error came from.

I still don't think stack traces are useful in all cases. Maybe just for adaptor errors?

@josephjclark
Copy link
Collaborator Author

josephjclark commented Jun 24, 2024

From mailchimp:

image

Not even sure I have any context. I think it's failing to parse the response body from post()?

@josephjclark josephjclark self-assigned this Jun 28, 2024
@josephjclark josephjclark moved this from In review to In progress in v2 Jun 28, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in v2 Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants