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

Fix: get output value #334

Merged
merged 1 commit into from
Jun 12, 2024
Merged

Conversation

dblock
Copy link
Member

@dblock dblock commented Jun 11, 2024

Description

On top of #333.

This bug shows up if you reference output that doesn't exist, or if a chapter fails and is referenced in an epilogue.

To reproduce:

  1. Manually create the model in tests/ml/model_groups.yaml.
  2. Run.
/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryOutputs.ts:34
    return this.outputs[chapter_id].get_output(output_name)
                                    ^
TypeError: Cannot read properties of undefined (reading 'get_output')
    at StoryOutputs.get_output_value (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryOutputs.ts:34:37)
    at StoryOutputs.resolve_string (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryOutputs.ts:52:19)
    at StoryOutputs.resolve_params (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryOutputs.ts:41:44)
    at ChapterReader.read (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/ChapterReader.ts:24:43)
    at SupplementalChapterEvaluator.evaluate (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/SupplementalChapterEvaluator.ts:26:53)
    at StoryEvaluator.#evaluate_supplemental_chapters (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryEvaluator.ts:88:93)
    at StoryEvaluator.evaluate (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/StoryEvaluator.ts:50:82)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TestRunner.run (/Users/dblock/source/opensearch-project/opensearch-api-specification/dblock-opensearch-api-specification/tools/src/tester/TestRunner.ts:33:26)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dblock dblock added the skip-changelog No need to update CHANGELOG. label Jun 11, 2024
Copy link
Contributor

github-actions bot commented Jun 11, 2024

Changes Analysis

Commit SHA: 49f9506
Comparing To SHA: ababab0

API Changes

Summary

NO CHANGES

Report

The full API changes report is available at: https://github.com/opensearch-project/opensearch-api-specification/actions/runs/9482775072/artifacts/1593732605

API Coverage

Before After Δ
Covered (%) 483 (47.31 %) 483 (47.31 %) 0 (0 %)
Uncovered (%) 538 (52.69 %) 538 (52.69 %) 0 (0 %)
Unknown 24 24 0

Comment on lines +34 to +35
const output = this.outputs[chapter_id]
return output !== undefined ? output.get_output(output_name) : undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to just use optional chaining here:

Suggested change
const output = this.outputs[chapter_id]
return output !== undefined ? output.get_output(output_name) : undefined
return this.outputs[chapter_id]?.get_output(output_name)

Copy link
Member Author

Choose a reason for hiding this comment

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

You can't because this is a Record<string, ChapterOutput> and the type system is not smart enough to know that the value can be undefined.

@dblock dblock force-pushed the fix-get_output_value branch from e22ae4c to 49f9506 Compare June 12, 2024 12:42
@Xtansia Xtansia merged commit 6601633 into opensearch-project:main Jun 12, 2024
8 checks passed
@dblock dblock deleted the fix-get_output_value branch June 12, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog No need to update CHANGELOG.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants