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

Return a more useful error when authType is omitted #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MatthewWilkes
Copy link

The new authType parameter is necessary to distinguish between the two Config types, with makeBlobServiceClient having different paths through a switch depending on its value to narrow the type between the two possible values. When upgrading from 3.3.0 this value won't be set, so users must explicitly set it to 'default' to maintain the current behaviour, however the default handler throws an error with the config object, which results in the user-facing error [2024-02-06 17:36:10.217] error: [object Object].

This change replaces throwing the config with throwing a human-readable string explaining the issue.

The new `authType` parameter is necessary to distinguish between the two Config types, with `makeBlobServiceClient` having different paths through a switch depending on its value to narrow the type between the two possible values. When upgrading from 3.3.0 this value won't be set, so users must explicitly set it to `'default'` to maintain the current behaviour, however the default handler throws an error with the config object, which results in the user-facing error `[2024-02-06 17:36:10.217] error: [object Object]`.

This change replaces throwing the config with throwing a human-readable string explaining the issue.
@MatthewWilkes
Copy link
Author

Thanks for 3.4.0, by the way :)

@@ -85,8 +85,7 @@ function makeBlobServiceClient(config: Config) {
return new BlobServiceClient(serviceBaseURL, new DefaultAzureCredential());
}
default: {
const exhaustiveCheck: never = config;
throw new Error(exhaustiveCheck);
throw new Error('config.authType value is not supported');
Copy link
Contributor

@fardarter fardarter Feb 15, 2024

Choose a reason for hiding this comment

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

You need the never check for Typescript so that it's exhaustive. That said, there's probably some way to make more humane. See here: https://medium.com/technogise/type-safe-and-exhaustive-switch-statements-aka-pattern-matching-in-typescript-e3febd433a7a

Copy link
Contributor

Choose a reason for hiding this comment

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

@jakeFeldman Would you be open to something like zod for IO type validation? https://www.npmjs.com/package/zod

Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer to keep the bundle size as small as possible. Looks like zod is about 13.2 kb when gzipped. Happy to explore adding this if it will help prevent this issue for users

Copy link
Contributor

Choose a reason for hiding this comment

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

@jakeFeldman Zod would just help to declare a schema for incoming variables and would be able to emit some useful errors.

If there is a way to gain more type safety on incoming variables in the way the plugin is provided to strapi, that would be better, but out of my expertise.

Copy link

@TamasHodi TamasHodi Nov 14, 2024

Choose a reason for hiding this comment

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

IMHO, merging this PR would be useful and could hurt noone.
Today, we've encountered this shady error after upgrading from 3.1.3 to 3.4.0.
It would be nice to see this human-readable error message ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

@TamasHodi It would harm the ability of the code to compile.

The author just needs to retain the never and enrich with a message.

Copy link
Owner

@jakeFeldman jakeFeldman Nov 16, 2024

Choose a reason for hiding this comment

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

@TamasHodi yes the package could handle this better. @fardarter I'd be okay moving to zod if someone wants to take on the changes. If not, happy to update just to using the never type as well. Sorry I don't have the bandwidth to take this on right now but will review and publish any changes. Thanks again

@medevod medevod mentioned this pull request Dec 6, 2024
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.

4 participants