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

feat(union): add details to union errors #276

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

Conversation

johngeorgewright
Copy link
Contributor

This is a simple workaround for #275 providing details on all validation errors.

@yuhr
Copy link
Collaborator

yuhr commented Aug 7, 2021

Thanks I really appreciate this, but changing the failcode is a breaking change. Let me postpone merging this until the next major version.

P.S. I'm not saying that we shouldn't change the failcode. CONTENT_INCORRECT seems the right way to represent the error, as Union is one of the complex runtypes which have contents.

@yuhr yuhr added this to the Runtypes 7 milestone Aug 16, 2021
@yuhr yuhr added this to To do in Development Sep 5, 2021
BREAKING CHANGE: Union failcode has changed from TYPE_INCORRECT to
CONTENT_INCORRECT.

Fixes runtypes#275
@yuhr
Copy link
Collaborator

yuhr commented Sep 12, 2021

@johngeorgewright Thanks rebasing this, but basically I don't want to require PR authors to do it by themselves. I'm working on other tasks, and I believe you will feel it tiresome if you need rebasing/merging upstream every time any update occurs. Please leave it to me 😉

else if (validation.details) details.push(validation.details);
else details.push(validation.message);
}
return FAILURE.CONTENT_INCORRECT(self, details);

Choose a reason for hiding this comment

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

Hi. What if we split these changes into 2 PRs?

PR1: return code: TYPE_INCORRECT but with details
PR2: change code to CONTENT_INCORRECT

In this case PR1 does not have breaking changed, it can be merged in minor release

Suggested change
return FAILURE.CONTENT_INCORRECT(self, details);
const fail = FAILURE.CONTENT_INCORRECT(self, details);
// TODO: remove this code hack in next major release
fail.code = Failcode.TYPE_INCORRECT;
return fail;

Choose a reason for hiding this comment

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

@yuhr what do you think?
would you merge this PR if it preserves code: TYPE_INCORRECT but still adding details?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, sounds neat but how we should format the error message might differ between TYPE_INCORRECT and CONTENT_INCORRECT (not sure but probably), so let me proceed #296 before taking action on this. Thanks suggestion!

Choose a reason for hiding this comment

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

Is this something that can be revisited? As more versions are published, it gets harder to keep up-to-date using a fork in a git reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants