dyne / slangroom

Enhance zencode smart contracts with your slang
https://dyne.org/slangroom/
GNU Affero General Public License v3.0
5 stars 1 forks source link

Improve error on not provided parameters #172

Closed matteo-cristino closed 6 days ago

matteo-cristino commented 2 weeks ago

Since the improvements in error reporting done in slangroom one thing (along with zenroom error that are next to be done) has been left behind. The error returned by fetch/fethOpne/fetchonnect https://github.com/dyne/slangroom/blob/de0850af5fbd15b5996a55a72aab551ea4fecd33/pkg/core/src/plugin.ts#L535-L542

In case a variable used by a statement, that uses fetch, is not found the error that the user would see is just

Error: the parameter isn't provided: ${parameters_name}

In order to have better error reporting (with lines, colour and so on) also in this case the only thing that I see is to modify all ctx.fetch with

fetch(lhs: string): PluginResult {
    const val = this.get(lhs);
    if (!val) return {ok: false, error: new MissingVariableError(`the parameter isn't provided: ${lhs}`)});
    return {ok: true, value: val};
 }

and modify where it is called with

const fetchRes = ctx.fetch("value_name");
if (!fetchRes.ok) then return ctx.fail(fetchRes.error);

In the same way it will be done for fetchOpen and fetchConnect.

Any better idea? 💡

puria commented 1 week ago

No it's ok to me to propagate the error, since we can't know how the fetch sentences will be implemented in plugins

matteo-cristino commented 1 week ago

We could do somithing like this in slangroom.ts

try {
  // slangrom_execute_statement
} catch(e) {
  if (e instanceof FetchError) {
    // throw nice colored error
  }
  throw e; // left for wrong no catched error in the plugins (should not happen)
}

or is it not worth it in you opinion?

puria commented 1 week ago

IMHO not needed