• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 236

26 Apr 2025 09:05AM UTC coverage: 74.134% (+0.08%) from 74.053%
236

push

circleci

leeonky
Update version

8048 of 10856 relevant lines covered (74.13%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.09
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/DalException.java
1
package com.github.leeonky.dal.runtime;
2

3
import com.github.leeonky.interpreter.InterpreterException;
4

5
import java.io.PrintWriter;
6
import java.io.StringWriter;
7
import java.util.Optional;
8

9
public class DalException extends InterpreterException {
10
    private final Throwable cause;
11

12
    public DalException(String message, int position) {
13
        this(message, position, Position.Type.CHAR, null);
1✔
14
    }
1✔
15

16
    public DalException(String message, int position, Throwable cause) {
17
        this(message, position, Position.Type.CHAR, cause);
×
18
    }
×
19

20
    public DalException(String message, int position, Position.Type type) {
21
        this(message, position, type, null);
×
22
    }
×
23

24
    public DalException(String message, int position, Position.Type type, Throwable cause) {
25
        super(message, position, type);
1✔
26
        this.cause = cause;
1✔
27
    }
1✔
28

29
    public DalException(int position, Throwable cause) {
30
        this(null, position, Position.Type.CHAR, cause);
1✔
31
    }
1✔
32

33
    public DalException(int position, Position.Type type, Throwable cause) {
34
        this(null, position, type, cause);
×
35
    }
×
36

37
    public static Optional<Throwable> extractException(Throwable e) {
38
        if (e instanceof UserRuntimeException)
1✔
39
            return Optional.ofNullable(e.getCause());
1✔
40
        if (e.getCause() == null)
1✔
41
            return Optional.empty();
1✔
42
        return extractException(e.getCause());
1✔
43
    }
44

45
    @Override
46
    public Throwable getCause() {
47
        return cause;
1✔
48
    }
49

50
    @Override
51
    public String getMessage() {
52
        return buildMessage(this, super.getMessage());
1✔
53
    }
54

55
    @Override
56
    public String toString() {
57
        return getMessage();
×
58
    }
59

60
    public static String buildMessage(Throwable e, String message) {
61
        if (message != null && !message.isEmpty()) {
1✔
62
            Throwable cause = e.getCause();
1✔
63
            if (cause != null)
1✔
64
                return message + "\n" + clauseInfo(cause);
1✔
65
            return message;
1✔
66
        }
67
        Throwable cause = e.getCause();
1✔
68
        if (cause != null)
1✔
69
            return clauseInfo(cause);
1✔
70
        return e.getClass().getName();
1✔
71
    }
72

73
    private static String clauseInfo(Throwable cause) {
74
        String info = cause.toString();
1✔
75
        if (cause instanceof UserRuntimeException) {
1✔
76
            StringWriter writer = new StringWriter();
1✔
77
            cause.getCause().printStackTrace(new PrintWriter(writer));
1✔
78
            return writer.toString();
1✔
79
        }
80
        return info;
1✔
81
    }
82

83
    public static RuntimeException locateError(Throwable e, int positionBegin) {
84
        if (e instanceof InterpreterException || e instanceof ExpressionException)
1✔
85
            return (RuntimeException) e;
1✔
86
        if (e instanceof AssertionError)
1✔
87
            return new AssertionFailure(e.getMessage(), positionBegin);
1✔
88
        return new DalException(positionBegin, e);
1✔
89
    }
90

91
    public static Throwable buildUserRuntimeException(Throwable error) {
92
        if (error instanceof DalRuntimeException
1✔
93
                || error instanceof UserRuntimeException
94
                || error instanceof AssertionError
95
                || error instanceof ExpressionException
96
                || error instanceof InterpreterException)
97
            return error;
1✔
98
        return new UserRuntimeException(error);
1✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc