Skip to content

Conversation

@maxy-shpfy
Copy link
Collaborator

@maxy-shpfy maxy-shpfy commented Dec 2, 2025

Description

Added a new componentSpecFromYaml function in utils/yaml.ts that safely parses YAML text into a ComponentSpec object with proper validation. This function replaces the direct use of yaml.load() in the component service, adding type checking and validation to prevent invalid component specifications.

Type of Change

  • Improvement
  • Cleanup/Refactor

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Test Instructions

  1. No functional changes to the app
  2. No regression should be found across the app

Copy link
Collaborator Author

maxy-shpfy commented Dec 2, 2025

@maxy-shpfy maxy-shpfy force-pushed the 12-02-refactoring_introduce_componentspecfromyaml branch from c0d3743 to 4e9e235 Compare December 2, 2025 17:14
@maxy-shpfy maxy-shpfy force-pushed the 12-01-fix_component_text_corruption_in_duplicate_dialog branch from 02da690 to 80ed20c Compare December 2, 2025 17:14
@maxy-shpfy maxy-shpfy changed the base branch from 12-01-fix_component_text_corruption_in_duplicate_dialog to graphite-base/1460 December 3, 2025 15:52
@maxy-shpfy maxy-shpfy force-pushed the 12-02-refactoring_introduce_componentspecfromyaml branch from 4e9e235 to 080f235 Compare December 3, 2025 15:55
@graphite-app graphite-app bot changed the base branch from graphite-base/1460 to master December 3, 2025 15:55
@maxy-shpfy maxy-shpfy force-pushed the 12-02-refactoring_introduce_componentspecfromyaml branch 2 times, most recently from 5469c24 to 182f57a Compare December 3, 2025 18:54
@maxy-shpfy maxy-shpfy marked this pull request as ready for review December 3, 2025 19:01
Comment on lines +19 to +32
class ComponentSpecParsingError extends Error {
readonly name = "ComponentSpecParsingError";

constructor(
message: string,
public readonly extra: {
yamlText?: string;
loadedSpec?: any;
} = {},
) {
super(message);
}
}

Copy link
Collaborator

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;
}

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

@maxy-shpfy maxy-shpfy force-pushed the 12-02-refactoring_introduce_componentspecfromyaml branch 2 times, most recently from 0675eb2 to 27592d1 Compare December 3, 2025 20:04
@maxy-shpfy maxy-shpfy requested a review from Mbeaulne December 3, 2025 22:00
Copy link
Collaborator

@camielvs camielvs left a 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:

  1. Split named errors into its own PR
  2. We follow this very rapidly to add named errors elsewhere and minimize the duration of any discrepancy and potential (new) tech debt

Copy link
Collaborator Author

maxy-shpfy commented Dec 4, 2025

Merge activity

  • Dec 4, 5:28 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 4, 5:29 PM UTC: Graphite rebased this pull request as part of a merge.
  • Dec 4, 5:30 PM UTC: @maxy-shpfy merged this pull request with Graphite.

@maxy-shpfy maxy-shpfy force-pushed the 12-02-refactoring_introduce_componentspecfromyaml branch from 27592d1 to 7d23214 Compare December 4, 2025 17:28
@maxy-shpfy maxy-shpfy merged commit 40c05c1 into master Dec 4, 2025
5 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.

4 participants