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

Add better error for MaxIterationsReached #7411

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/javascript/interpreter/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export type RuntimeErrorType =
| 'ExpectedFunctionNotFound'
| 'ExpectedFunctionHasWrongArguments'
| 'InvalidNestedFunction'
| 'MaxIterationsReached'

export type StaticErrorType =
| DisabledLanguageFeatureErrorType
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/interpreter/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class Executor {
statement.location.absolute.begin + 22
)
)
this.error('InfiniteLoop', errorLoc)
this.error('MaxIterationsReached', errorLoc, { maxIterations })
}

this.guardInfiniteLoop(statement.location)
Expand Down
1 change: 1 addition & 0 deletions app/javascript/interpreter/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"CouldNotFindFunction": "Jiki couldn't find a function with the name `{{name}}`.",
"CouldNotFindFunctionWithSuggestion": "Jiki couldn't find a function with the name `{{name}}`. Maybe you meant to use the `{{suggestion}}` function instead?",
"InfiniteLoop": "Your code ran for too long and we stopped it to prevent an infinite loop.",
"MaxIterationsReached": "You hit the maximum number of iterations allowed in this exercise ({{maxIterations}}). Try and find a more efficient way to solve the exercise.",
"InvalidBinaryExpression": "Invalid binary expression",
"InvalidExpression": "Invalid expression",
"InvalidIndexGetterTarget": "Can't index object, only dictionaries and arrays can be indexed'.",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/interpreter/locales/system/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"CouldNotFindFunction": "CouldNotFindFunction: name: {{name}}",
"CouldNotFindFunctionWithSuggestion": "CouldNotFindFunctionWithSuggestion: name: {{name}}, suggestion: {{suggestion}}",
"InfiniteLoop": "InfiniteLoop",
"MaxIterationsReached": "MaxIterationsReached: maxIterations: {{maxIterations}}",
"InvalidBinaryExpression": "InvalidBinaryExpression",
"InvalidExpression": "InvalidExpression",
"InvalidIndexGetterTarget": "InvalidIndexGetterTarget",
Expand Down
17 changes: 17 additions & 0 deletions test/javascript/interpreter/runtimeErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,21 @@ describe('Runtime errors', () => {
)
})
})
test('MaxIterationsReached', () => {
const code = `repeat_until_game_over do
end`

const maxIterations = 50
const { frames } = interpret(code, {
languageFeatures: { maxRepeatUntilGameOverIterations: maxIterations },
})
expectFrameToBeError(
frames[0],
'repeat_until_game_over',
'MaxIterationsReached'
)
expect(frames[0].error!.message).toBe(
`MaxIterationsReached: maxIterations: ${maxIterations}`
)
})
})
Loading