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

Improve error handling #149

Merged
merged 14 commits into from
Jun 27, 2023
Merged

Improve error handling #149

merged 14 commits into from
Jun 27, 2023

Conversation

NickHeiner
Copy link
Contributor

This improves our error handling to be more structured + consistent. Now, when an AI.JSX run throws an error, we see this in the console:

[11:48:44.165] ERROR (ai-jsx/43657): Rendering element <OpenAIChatModel> failed with exception: AI.JSX(1021): ChatCompletion must have at least child that's a SystemMessage, UserMessage, AssistantMessage, FunctionCall, or FunctionResponse, but no such children were found.

This may be due to a mistake in your code.

Need help?
* Discord: https://discord.com/channels/1065011484125569147/1121125525142904862
* Docs: https://docs.ai-jsx.com/
* GH: https://github.com/fixie-ai/ai-jsx/issues
    exception: {
      "code": 1021,
      "kind": "user",
      "metadata": {}
    }
    renderId: "6c0aebe3-75cd-4048-929b-dfc44f8bd9ca"
    element: "<OpenAIChatModel>"

Key elements:

  1. Making it clear whether the error is within the dev's power to fix.
  2. CTAs to get help.
  3. Programmatically-available metadata on all errors.
  4. Statically-known error codes. (Right now, there's no mechanism to prevent people from duplicating codes – if that ends up becoming annoying, we can revisit.)

@vercel
Copy link

vercel bot commented Jun 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-jsx-docs ❌ Failed (Inspect) Mar 19, 2024 2:17pm
ai-jsx-nextjs-demo 🔄 Building (Inspect) Mar 19, 2024 2:17pm
ai-jsx-tutorial-nextjs 🔄 Building (Inspect) Mar 19, 2024 2:17pm

@vercel
Copy link

vercel bot commented Jun 26, 2023

@NickHeiner is attempting to deploy a commit to the FixieAI Team on Vercel.

A member of the Team first needs to authorize it.

packages/ai-jsx/src/core/core.ts Outdated Show resolved Hide resolved
export class AIJSXError extends Error {
constructor(
message: string,
public readonly code: number,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected that this is thrown exclusively by code that lives in AI.JSX itself?

Comment on lines 4 to 10
export type ErrorKind =
/** An error that is expected to occur, like a network failure. */
| 'runtime'
/** An error that's most likely caused by the user. */
| 'user'
/** An error that's most likely the fault of AI.JSX itself. */
| 'internal';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm skeptical that this is a useful classification in that I suspect it doesn't add material value in places where it's accurate with high confidence (e.g. OpenAI HTTP errors) and is otherwise likely to be inaccurate/confusing.

packages/ai-jsx/src/lib/error.ts Outdated Show resolved Hide resolved
packages/ai-jsx/src/lib/error.ts Outdated Show resolved Hide resolved
@NickHeiner NickHeiner merged commit 92c34d9 into fixie-ai:main Jun 27, 2023
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants