Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2c038eba9bc8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8c35779d4f1a
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 16, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6d4af5a View commit details
  2. Copy the full SHA
    8c35779 View commit details
Showing with 29 additions and 92 deletions.
  1. +2 −2 lib/ruby/truffle/jruby+truffle/lib/runner.rb
  2. +27 −90 truffle/src/main/java/org/jruby/truffle/language/backtrace/BacktraceFormatter.java
4 changes: 2 additions & 2 deletions lib/ruby/truffle/jruby+truffle/lib/runner.rb
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ module OptionBlocks
readme: {
help: ['-h', '--help', 'Show this message', STORE_NEW_VALUE, false]
}
}
}.each { |group, options| options.each { |name, definition| definition.last.freeze } }
end

begin
@@ -334,7 +334,7 @@ def construct_default_options

def self.default_option_values(group_options)
group_options.each_with_object({}) do |(option, data), group_option_defaults|
*args, block, default = data
*args, block, default = data
unless [TrueClass, FalseClass, NilClass, Fixnum].any? { |v| v === default }
default = default.clone
end
Original file line number Diff line number Diff line change
@@ -95,19 +95,9 @@ public List<String> formatBacktrace(RubyContext context, DynamicObject exception
final List<Activation> activations = backtrace.getActivations();
final ArrayList<String> lines = new ArrayList<>();

try {
lines.add(formatInLine(activations, exception));
} catch (Exception e) {
if (context.getOptions().EXCEPTIONS_PRINT_JAVA) {
e.printStackTrace();
}

lines.add(String.format("(exception %s %s", e.getMessage(), e.getStackTrace()[0].toString()));
}

for (int n = 1; n < activations.size(); n++) {
for (int n = 0; n < activations.size(); n++) {
try {
lines.add(formatFromLine(activations, n));
lines.add(formatLine(activations, n, exception));
} catch (Exception e) {
if (context.getOptions().EXCEPTIONS_PRINT_JAVA) {
e.printStackTrace();
@@ -124,84 +114,7 @@ public List<String> formatBacktrace(RubyContext context, DynamicObject exception
return lines;
}

private String formatInLine(List<Activation> activations, DynamicObject exception) {
final StringBuilder builder = new StringBuilder();

if (activations.isEmpty()) {
throw new UnsupportedOperationException("At least one activation is required.");
}

final Activation activation = activations.get(0);

if (activation == Activation.OMITTED_LIMIT) {
return OMITTED_LIMIT;
}

if (activation == Activation.OMITTED_UNUSED) {
return OMITTED_UNUSED;
}

if (activation.getCallNode().getRootNode() instanceof RubyRootNode) {
final SourceSection sourceSection = activation.getCallNode().getEncapsulatingSourceSection();
final SourceSection reportedSourceSection;
final String reportedName;

if (isCore(sourceSection) && !flags.contains(FormattingFlags.INCLUDE_CORE_FILES)) {
reportedSourceSection = nextUserSourceSection(activations, 1);
reportedName = activation.getMethod().getName();
} else {
reportedSourceSection = sourceSection;
reportedName = reportedSourceSection.getIdentifier();
}

if (reportedSourceSection == null || reportedSourceSection.getSource() == null) {
builder.append("???");
} else {
builder.append(reportedSourceSection.getSource().getName());
builder.append(":");
builder.append(reportedSourceSection.getStartLine());
builder.append(":in `");
builder.append(reportedName);
builder.append("'");
}
} else {
builder.append(formatForeign(activation.getCallNode()));
}

if (!flags.contains(FormattingFlags.OMIT_EXCEPTION) && exception != null) {
String message;
try {
Object messageObject = context.send(exception, "message", null);
if (RubyGuards.isRubyString(messageObject)) {
message = messageObject.toString();
} else {
message = Layouts.EXCEPTION.getMessage(exception).toString();
}
} catch (RaiseException e) {
message = Layouts.EXCEPTION.getMessage(exception).toString();
}

builder.append(": ");
builder.append(message);
builder.append(" (");
builder.append(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getName());
builder.append(")");
}

return builder.toString();
}

private String formatFromLine(List<Activation> activations, int n) {
final String formattedLine = formatLine(activations, n);

if (flags.contains(FormattingFlags.OMIT_FROM_PREFIX)) {
return formattedLine;
} else {
return "\tfrom " + formattedLine;
}
}

public String formatLine(List<Activation> activations, int n) {
public String formatLine(List<Activation> activations, int n, DynamicObject exception) {
final Activation activation = activations.get(n);

if (activation == Activation.OMITTED_LIMIT) {
@@ -214,6 +127,10 @@ public String formatLine(List<Activation> activations, int n) {

final StringBuilder builder = new StringBuilder();

if (!flags.contains(FormattingFlags.OMIT_FROM_PREFIX) && n > 0) {
builder.append("\tfrom ");
}

if (activation.getCallNode().getRootNode() instanceof RubyRootNode) {
final SourceSection sourceSection = activation.getCallNode().getEncapsulatingSourceSection();
final SourceSection reportedSourceSection;
@@ -249,6 +166,26 @@ public String formatLine(List<Activation> activations, int n) {
builder.append(formatForeign(activation.getCallNode()));
}

if (!flags.contains(FormattingFlags.OMIT_EXCEPTION) && exception != null && n == 0) {
String message;
try {
Object messageObject = context.send(exception, "message", null);
if (RubyGuards.isRubyString(messageObject)) {
message = messageObject.toString();
} else {
message = Layouts.EXCEPTION.getMessage(exception).toString();
}
} catch (RaiseException e) {
message = Layouts.EXCEPTION.getMessage(exception).toString();
}

builder.append(": ");
builder.append(message);
builder.append(" (");
builder.append(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getName());
builder.append(")");
}

return builder.toString();
}