How to use @truffle/debug-utils - 10 common examples

To help you get started, we’ve selected a few @truffle/debug-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
const range = this.session.view(solidity.current.sourceRange);
    debug("range: %o", range);

    // We were splitting on OS.EOL, but it turns out on Windows,
    // in some environments (perhaps?) line breaks are still denoted by just \n
    const splitLines = str => str.split(/\r?\n/g);

    const lines = splitLines(source);
    const colorizedLines = splitLines(colorizedSource);

    this.config.logger.log("");

    //HACK -- the line-pointer formatter doesn't work right with colorized
    //lines, so we pass in the uncolored version too
    this.config.logger.log(
      DebugUtils.formatRangeLines(
        colorizedLines,
        range.lines,
        lines,
        contextBefore,
        contextAfter
      )
    );

    this.config.logger.log("");
  }
github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
// produces really weird output when there are errors. e.g.,
      //
      //   evalmachine.:1
      //   SAFE_EVAL_857712=a
      //   ^
      //
      //   ReferenceError: a is not defined
      //     at evalmachine.:1:1
      //     at ContextifyScript.Script.runInContext (vm.js:59:29)
      //
      // We want to hide this from the user if there's an error.
      e.stack = e.stack.replace(/SAFE_EVAL_\d+=/, "");
      if (!suppress) {
        this.config.logger.log(e);
      } else {
        this.config.logger.log(DebugUtils.formatValue(undefined, indent, true));
      }
    }
  }
}
github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
// converts all !<...> expressions to JS-valid selector requests
    const preprocessSelectors = expr => {
      const regex = /!<([^>]+)>/g;
      const select = "$"; // expect repl context to have this func
      const replacer = (_, selector) => `${select}("${selector}")`;

      return expr.replace(regex, replacer);
    };

    //if we're just dealing with a single variable, handle that case
    //separately (so that we can do things in a better way for that
    //case)
    let variable = raw.trim();
    if (variable in variables) {
      let formatted = DebugUtils.formatValue(variables[variable], indent);
      this.config.logger.log(formatted);
      this.config.logger.log();
      return;
    }

    //HACK
    //if we're not in the single-variable case, we'll need to do some
    //things to Javascriptify our variables so that the JS syntax for
    //using them is closer to the Solidity syntax
    variables = Codec.Format.Utils.Inspect.nativizeVariables(variables);

    let context = Object.assign(
      { $: this.select },

      variables
    );
github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
new RegExp("(?:1
      //   SAFE_EVAL_857712=a
      //   ^
      //
      //   ReferenceError: a is not defined
      //     at evalmachine.:1:1
      //     at ContextifyScript.Script.runInContext (vm.js:59:29)
      //
      // We want to hide this from the user if there's an error.
      e.stack = e.stack.replace(/SAFE_EVAL_\d+=/, "");
github trufflesuite / truffle / packages / core / lib / debug / interpreter.js View on Github external
} else {
          txSpinner.fail();
          loadFailed = true;
        }
      } else {
        loadFailed = true;
        this.printer.print(
          "Please unload the current transaction before loading a new one."
        );
      }
    }
    if (cmd === "T") {
      if (this.session.view(selectors.session.status.loaded)) {
        await this.session.unload();
        this.printer.print("Transaction unloaded.");
        this.setPrompt(DebugUtils.formatPrompt(this.network));
      } else {
        this.printer.print("No transaction to unload.");
        this.printer.print("");
      }
    }

    // Check if execution has (just now) stopped.
    if (this.session.view(trace.finished) && !alreadyFinished) {
      this.printer.print("");
      //check if transaction failed
      if (!this.session.view(evm.transaction.status)) {
        this.printer.print("Transaction halted with a RUNTIME ERROR.");
        this.printer.print("");
        this.printer.print(
          "This is likely due to an intentional halting expression, like assert(), require() or revert(). It can also be due to out-of-gas exceptions. Please inspect your transaction parameters and contract code to determine the meaning of this error."
        );
github trufflesuite / truffle / packages / core / lib / debug / interpreter.js View on Github external
start(terminate) {
    // if terminate is not passed, return a Promise instead
    if (terminate === undefined) {
      return util.promisify(this.start.bind(this))();
    }

    if (this.session.view(session.status.loaded)) {
      this.printer.printSessionLoaded();
    } else if (this.session.view(session.status.isError)) {
      this.printer.printSessionError();
    } else {
      this.printer.printHelp();
    }

    const prompt = this.session.view(session.status.loaded)
      ? DebugUtils.formatPrompt(this.network, this.txHash)
      : DebugUtils.formatPrompt(this.network);

    this.repl.start({
      prompt,
      interpreter: util.callbackify(this.interpreter.bind(this)),
      ignoreUndefined: true,
      done: terminate
    });
  }
github trufflesuite / truffle / packages / core / lib / debug / interpreter.js View on Github external
// if terminate is not passed, return a Promise instead
    if (terminate === undefined) {
      return util.promisify(this.start.bind(this))();
    }

    if (this.session.view(session.status.loaded)) {
      this.printer.printSessionLoaded();
    } else if (this.session.view(session.status.isError)) {
      this.printer.printSessionError();
    } else {
      this.printer.printHelp();
    }

    const prompt = this.session.view(session.status.loaded)
      ? DebugUtils.formatPrompt(this.network, this.txHash)
      : DebugUtils.formatPrompt(this.network);

    this.repl.start({
      prompt,
      interpreter: util.callbackify(this.interpreter.bind(this)),
      ignoreUndefined: true,
      done: terminate
    });
  }
github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
//note that pseudoThis contains no special characters
      new RegExp("(?:1
      //   SAFE_EVAL_857712=a
      //   ^
      //
      //   ReferenceError: a is not defined
      //     at evalmachine.:1:1
      //     at ContextifyScript.Script.runInContext (vm.js:59:29)
      //
      // We want to hide this from the user if there's an error.
github trufflesuite / truffle / packages / core / lib / debug / printer.js View on Github external
throw new Error("Unknown selector: %s", expr);
      }

      // throws its own exception
      result = this.session.view(selector);

      return result;
    };

    this.colorizedSources = {};
    for (const source of Object.values(
      this.session.view(solidity.info.sources)
    )) {
      const id = source.id;
      const uncolorized = source.source;
      const colorized = DebugUtils.colorize(uncolorized);
      this.colorizedSources[id] = colorized;
    }
  }
github microsoft / vscode-azure-blockchain-ethereum / src / debugAdapter / runtimeInterface.ts View on Github external
public async variables(/* args?: DebugProtocol.VariablesArguments */): Promise {
    if (this._session) {
      const variables = await this._session.variables();
      return truffleDebugUtils.nativize(variables);
    } else {
      return Promise.resolve({});
    }
  }