fix(muscript): disable formatting for intentional exceptions

This commit is contained in:
Johannes Frohnmeyer 2024-04-07 17:17:53 +02:00
parent 785e5ca5c5
commit 26edf52944
Signed by: Johannes
GPG Key ID: E76429612C2929F4
5 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,7 @@
package io.gitlab.jfronny.muscript.data.additional.libs;
public class IntentionalException extends RuntimeException {
public IntentionalException(String message) {
super(message);
}
}

View File

@ -385,7 +385,7 @@ public class StandardLib {
.and(callable(null));
public static DNull fail(DList args) {
if (args.size() > 1) throw new SignatureDesyncException("fail");
throw new RuntimeException(args.isEmpty() ? "Failed" : args.get(0).asString().getValue());
throw new IntentionalException(args.isEmpty() ? "Failed" : args.get(0).asString().getValue());
}
// Util

View File

@ -18,7 +18,7 @@ public non-sealed interface DCallable extends Dynamic {
if (!TypeMatcher.match(signature, argTypes)) {
List<DTypeCallable.Arg> extraArgs = argTypes.stream().map(s -> new DTypeCallable.Arg(null, s, false)).toList();
DTypeCallable callSignature = new DTypeCallable(extraArgs, null);
throw new IllegalArgumentException("Signature mismatch for " + getName() + ": expected <" + signature + "> but got <" + callSignature + ">");
throw new SignatureMismatchException(getName(), signature, callSignature);
}
}
return getValue().apply(args);

View File

@ -0,0 +1,10 @@
package io.gitlab.jfronny.muscript.data.dynamic;
import io.gitlab.jfronny.muscript.data.dynamic.type.DType;
import io.gitlab.jfronny.muscript.data.dynamic.type.DTypeCallable;
public class SignatureMismatchException extends IllegalArgumentException {
public SignatureMismatchException(String method, DType expected, DTypeCallable actual) {
super("Signature mismatch for " + method + ": expected <" + expected + "> but got <" + actual + ">");
}
}

View File

@ -11,11 +11,12 @@ import io.gitlab.jfronny.muscript.ast.extensible.ExtensibleNumberExpr;
import io.gitlab.jfronny.muscript.ast.extensible.ExtensibleStringExpr;
import io.gitlab.jfronny.muscript.ast.number.*;
import io.gitlab.jfronny.muscript.ast.string.*;
import io.gitlab.jfronny.muscript.core.CodeLocation;
import io.gitlab.jfronny.muscript.core.IDynamic;
import io.gitlab.jfronny.muscript.core.LocationalException;
import io.gitlab.jfronny.muscript.core.StackFrame;
import io.gitlab.jfronny.muscript.data.additional.context.Scope;
import io.gitlab.jfronny.muscript.data.additional.libs.IntentionalException;
import io.gitlab.jfronny.muscript.data.additional.libs.SignatureDesyncException;
import io.gitlab.jfronny.muscript.data.dynamic.*;
import io.gitlab.jfronny.muscript.data.dynamic.context.DynamicSerializer;
import io.gitlab.jfronny.muscript.data.dynamic.type.DTypeCallable;
@ -235,6 +236,8 @@ public class Runtime {
yield dc.call(arg);
} catch (LocationalException le) {
throw le.appendStack(new StackFrame.Raw(expr.location().file(), dc.getName(), e.callable().location().chStart()));
} catch (IntentionalException | SignatureDesyncException | SignatureMismatchException ex) {
throw new LocationalException(expr.location(), ex.getMessage(), ex);
} catch (RuntimeException ex) {
throw locationalException(expr, ex.getMessage(), ex);
}