-
Notifications
You must be signed in to change notification settings - Fork 1
refactoring: introduce componentSpecFromYaml #1460
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
refactoring: introduce componentSpecFromYaml #1460
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
c0d3743 to
4e9e235
Compare
02da690 to
80ed20c
Compare
80ed20c to
304f7b9
Compare
4e9e235 to
080f235
Compare
5469c24 to
182f57a
Compare
| class ComponentSpecParsingError extends Error { | ||
| readonly name = "ComponentSpecParsingError"; | ||
|
|
||
| constructor( | ||
| message: string, | ||
| public readonly extra: { | ||
| yamlText?: string; | ||
| loadedSpec?: any; | ||
| } = {}, | ||
| ) { | ||
| super(message); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? what are we using teh extra data for?
Can we just not return an error?
export function componentSpecFromYaml(yamlText: string): ComponentSpec {
const loadedSpec = yaml.load(yamlText);
if (typeof loadedSpec !== "object" || loadedSpec === null) {
throw new Error("Invalid component specification format");
}
// todo: consider advanced validation
if (!isValidComponentSpec(loadedSpec)) {
throw new Error("Invalid component specification format");
}
return loadedSpec;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to move away from using just "Errors". I`m ok to remove extra information if that would cause lot of debates (even though it's cheap and may help debugging just in case). But having named errors helps a lot while try/catch and overall error handling.
E.g. for this specific use-case failure of the parsing can be handled in some specific way https://github.com/TangleML/tangle-ui/blob/master/src/services/pipelineService.ts#L254
So . that's a more long-lasting move to have more precise error handling. Also when we start sending errors to Shopify Observe/Logs - having named errors becomes essential.
In nearest future we also should add linting rule to restrict using unnamed errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. I agree in principle with the idea, but I am not sure this PR specifically is the right place to start. Is it something we want to do gradually, or all at once?
Perhaps to unblock we would look at adding & using named errors as a separate PR and move to conversation over there?
0675eb2 to
27592d1
Compare
camielvs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this PR. I can see the tech debt melting away before my eyes.
However, I do agree with the sentiment that this may not be the place to start introducing a Named Error system. I would like to see either:
- Split named errors into its own PR
- We follow this very rapidly to add named errors elsewhere and minimize the duration of any discrepancy and potential (new) tech debt
Merge activity
|
27592d1 to
7d23214
Compare

Description
Added a new
componentSpecFromYamlfunction inutils/yaml.tsthat safely parses YAML text into a ComponentSpec object with proper validation. This function replaces the direct use ofyaml.load()in the component service, adding type checking and validation to prevent invalid component specifications.Type of Change
Checklist
Test Instructions