Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Oct 18, 2024
1 parent de37a83 commit 0dfa597
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/codegen/EmitVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static void handleAssignOperator(EmitterVisitor emitterVisitor, BinaryOperatorNo
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "setFromList", "(Lorg/perlonjava/runtime/RuntimeList;)Lorg/perlonjava/runtime/RuntimeArray;", true);
break;
default:
throw new IllegalArgumentException("Unsupported assignment context: " + lvalueContext);
throw new PerlCompilerException("Unsupported assignment context: " + lvalueContext);
}
if (emitterVisitor.ctx.contextType == RuntimeContextType.VOID) {
// Remove the value from the stack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.objectweb.asm.*;
import org.objectweb.asm.util.TraceClassVisitor;
import org.perlonjava.astnode.Node;
import org.perlonjava.runtime.PerlCompilerException;
import org.perlonjava.runtime.RuntimeContextType;

import java.io.PrintWriter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public static String generateClassName() {
public static String getVariableDescriptor(String varName) {
// Ensure the variable name is not empty
if (varName == null || varName.isEmpty()) {
throw new IllegalArgumentException("Variable name cannot be null or empty");
throw new PerlCompilerException("Variable name cannot be null or empty");
}

// Extract the first character of the variable name
Expand All @@ -63,7 +64,7 @@ public static String getVariableDescriptor(String varName) {
public static String getVariableClassName(String varName) {
// Ensure the variable name is not empty
if (varName == null || varName.isEmpty()) {
throw new IllegalArgumentException("Variable name cannot be null or empty");
throw new PerlCompilerException("Variable name cannot be null or empty");
}

// Extract the first character of the variable name
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/perlonjava/perlmodule/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void initialize() {

public static RuntimeList importSymbols(RuntimeArray args, int ctx) {
if (args.size() < 1) {
throw new IllegalArgumentException("Not enough arguments for import");
throw new PerlCompilerException("Not enough arguments for import");
}

// System.out.println("importSymbols: " + args);
Expand Down Expand Up @@ -65,7 +65,7 @@ public static RuntimeList importSymbols(RuntimeArray args, int ctx) {
if (tagSymbols != null) {
tagArray.elements.addAll(tagSymbols.elements);
} else {
throw new IllegalArgumentException("Unknown export tag: " + tagName);
throw new PerlCompilerException("Unknown export tag: " + tagName);
}
} else {
tagArray.elements.add(symbolObj);
Expand All @@ -86,10 +86,10 @@ public static RuntimeList importSymbols(RuntimeArray args, int ctx) {
if (symbolRef.type == RuntimeScalarType.CODE) {
getGlobalCodeRef(caller + "::" + symbolString).set(symbolRef);
} else {
throw new IllegalArgumentException("Subroutine " + symbolString + " not found in package " + packageName);
throw new PerlCompilerException("Subroutine " + symbolString + " not found in package " + packageName);
}
} else {
throw new IllegalArgumentException("Subroutine " + symbolString + " not allowed for export in package " + packageName);
throw new PerlCompilerException("Subroutine " + symbolString + " not allowed for export in package " + packageName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/perlmodule/Parent.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void initialize() {

public static RuntimeList importParent(RuntimeArray args, int ctx) {
if (args.size() < 1) {
throw new IllegalArgumentException("Not enough arguments for parent::import");
throw new PerlCompilerException("Not enough arguments for parent::import");
}

RuntimeScalar packageScalar = args.shift();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/runtime/FileTestOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static RuntimeScalar getFileTimeDifference(Path path, String operator) t
fileTime = ((FileTime) Files.getAttribute(path, "creationTime", LinkOption.NOFOLLOW_LINKS)).toMillis();
break;
default:
throw new IllegalArgumentException("Invalid time operator: " + operator);
throw new PerlCompilerException("Invalid time operator: " + operator);
}

double daysDifference = (currentTime - fileTime) / (1000.0 * 60 * 60 * 24);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/runtime/NameNormalizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static String normalizeVariableName(String variable, String defaultPackag

public static String moduleToFilename(String moduleName) {
if (moduleName == null || moduleName.isEmpty()) {
throw new IllegalArgumentException("Module name cannot be null or empty");
throw new PerlCompilerException("Module name cannot be null or empty");
}

// Replace '::' with '/' and append '.pm'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/perlonjava/runtime/RuntimeVecLvalue.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RuntimeScalar set(RuntimeScalar value) {
try {
// Use Vec.set to update the parent string
Vec.set(args, new RuntimeScalar(newValue));
} catch (IllegalArgumentException e) {
} catch (PerlCompilerException e) {
throw new RuntimeException("Invalid vec operation: " + e.getMessage());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/perlonjava/runtime/ScalarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public class ScalarUtils {
*
* @param str The input string to be incremented
* @return The incremented string
* @throws IllegalArgumentException if the input string is null or empty
* @throws PerlCompilerException if the input string is null or empty
*/
public static String incrementPlainString(String str) {
if (str == null || str.isEmpty()) {
return str; // Consider throwing an IllegalArgumentException instead
return str; // Consider throwing an PerlCompilerException instead
}

char lastChar = str.charAt(str.length() - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/perlonjava/runtime/Vec.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.nio.ByteOrder;

public class Vec {
public static RuntimeScalar vec(RuntimeList args) throws IllegalArgumentException {
public static RuntimeScalar vec(RuntimeList args) throws PerlCompilerException {
RuntimeScalar strScalar = (RuntimeScalar) args.elements.get(0);
String str = strScalar.toString();
int offset = ((RuntimeScalar) args.elements.get(1)).getInt();
Expand Down Expand Up @@ -52,7 +52,7 @@ public static RuntimeScalar vec(RuntimeList args) throws IllegalArgumentExceptio
return new RuntimeVecLvalue(strScalar, offset, bits, value);
}

public static RuntimeScalar set(RuntimeList args, RuntimeScalar value) throws IllegalArgumentException {
public static RuntimeScalar set(RuntimeList args, RuntimeScalar value) throws PerlCompilerException {
String str = args.elements.get(0).toString();
int offset = ((RuntimeScalar) args.elements.get(1)).getInt();
int bits = ((RuntimeScalar) args.elements.get(2)).getInt();
Expand Down

0 comments on commit 0dfa597

Please sign in to comment.