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

Detect error code collisions #3

Open
jhnns opened this issue Dec 3, 2015 · 8 comments
Open

Detect error code collisions #3

jhnns opened this issue Dec 3, 2015 · 8 comments

Comments

@jhnns
Copy link
Member

jhnns commented Dec 3, 2015

Within the same application, there should not be more than one error class associated with a given error code. Erroz should detect these collisions and throw an error.

var FileNotFound = erroz({
    code: "not-found"
});
// Should throw an Duplicate error code error
var UserNotFound = erroz({
    code: "not-found"
});
@jhnns
Copy link
Member Author

jhnns commented Dec 3, 2015

I'm not sure if that's useful for all use cases, but it is surely useful for many.

@meaku
Copy link
Member

meaku commented Dec 7, 2015

Nice idea! But it assumes that you have some kind of registry for your errors and it might be inconvenient to bind it to the erroz "instance". How about making it configurable?

@jhnns
Copy link
Member Author

jhnns commented Dec 8, 2015

Yes... but a boolean switch on the erroz object like erroz.uniqueErrorCodes = true feels kind of wrong. What about creating "domains":

// creating domains for error codes
erroz.domain("api");
erroz.domain("db");

// later
erroz.domain.api({
    code: "not-found"
}); // ok
erroz.domain.db({
    code: "not-found"
}); // ok
erroz.domain.api({
    code: "not-found"
}); // throws Duplicate Error Code

With ES2015 Proxies, we could even omit the first step of creating domains. This would be done implicitly by intercepting all property retrievals on erroz.domain.

@meaku
Copy link
Member

meaku commented Dec 8, 2015

Sounds good! I'd still add erroz.uniqueErrorCodes = true with default = true to make this behavior configurable.

Scheduled for the next release 👍

@jhnns
Copy link
Member Author

jhnns commented Dec 8, 2015

But if we have domains, we don't need an erroz.uniqueErrorCodes option imho

@meaku
Copy link
Member

meaku commented Dec 8, 2015

But domains are optional right? If we only add the feature for domains its fine to kick the option. Otherwise i would add the option for "global" errors.

@jhnns
Copy link
Member Author

jhnns commented Dec 8, 2015

Yes, domains are optional. But if you don't use domains, erroz won't check for duplicate error codes (just the current behavior)

@meaku
Copy link
Member

meaku commented Dec 8, 2015

Easy ™️

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

No branches or pull requests

2 participants