Skip to content

improve: error handling for scripts #4082

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

Merged

Conversation

pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Feb 21, 2025

Description

Improved Error Handling for Request Scripts

What Changed

  • Added error catching and reporting for post-response scripts and test scripts
  • Instead of failing the entire request when scripts fail, now captures and reports script errors separately
  • Added a new scriptErrors field in the response object to track both post-response error
  • Enhanced error formatting and handling in the collections reducer
image

}

// Run JSHint with predefined Bruno globals
if (!window.JSHINT(text, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be defined as a const

const JS_LINT_OPTIONS = {
    esversion: 11,
    expr: true,
    asi: true,
    undef: true,
    browser: true,
    devel: true,
    predef: {
      'bru': false,
      'req': false,
      'res': false
    }
 }

also other keywords like test and expect need to predef

@@ -357,7 +410,23 @@ export default class CodeEditor extends React.Component {

_onEdit = () => {
if (!this.ignoreChangeEvent && this.editor) {
this.editor.setOption('lint', this.editor.getValue().trim().length > 0 ? this.lintOptions : false);
if (this.props.mode === 'javascript') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the lint options could be defined once in the constructor based on mode and used everywhere

@@ -731,38 +766,38 @@ const registerNetworkIpc = (mainWindow) => {

const testFile = get(request, 'tests');
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime({ runtime: scriptingConfig?.runtime });
Copy link
Collaborator

Choose a reason for hiding this comment

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

nothing got modified here except indentation ?

);
} catch (error) {
console.error('Post-response script error:', error);
postResponseError = serializeError(error);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could be a new different event like request-post-script-error or something

@helloanoop helloanoop dismissed their stale review March 10, 2025 14:21

Dismissing Review

@helloanoop helloanoop merged commit 0fbbe8a into usebruno:main Mar 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants