Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stackTrace prop to Exception message #182

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add `stackTrace` prop to `Exception` message ([#182](https://github.com/cucumber/messages/pull/182))

## [23.0.0] - 2023-11-01
### Added
Expand Down
1 change: 1 addition & 0 deletions cpp/include/cucumber/messages/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct exception
{
std::string type;
std::optional<std::string> message;
std::optional<std::string> stack_trace;

std::string to_string() const;

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/cucumber-messages/cucumber/messages/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exception::to_string() const

cucumber::messages::to_string(oss, "type=", type);
cucumber::messages::to_string(oss, ", message=", message);
cucumber::messages::to_string(oss, ", stack_trace=", stack_trace);

return oss.str();
}
Expand All @@ -21,6 +22,7 @@ exception::to_json(json& j) const
{
cucumber::messages::to_json(j, camelize("type"), type);
cucumber::messages::to_json(j, camelize("message"), message);
cucumber::messages::to_json(j, camelize("stack_trace"), stack_trace);
}

std::string
Expand Down
5 changes: 3 additions & 2 deletions go/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type Envelope struct {
}

type Exception struct {
Type string `json:"type"`
Message string `json:"message,omitempty"`
Type string `json:"type"`
Message string `json:"message,omitempty"`
StackTrace string `json:"stackTrace,omitempty"`
}

type GherkinDocument struct {
Expand Down
19 changes: 16 additions & 3 deletions java/src/generated/java/io/cucumber/messages/types/Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
public final class Exception {
private final String type;
private final String message;
private final String stackTrace;

public Exception(
String type,
String message
String message,
String stackTrace
) {
this.type = requireNonNull(type, "Exception.type cannot be null");
this.message = message;
this.stackTrace = stackTrace;
}

/**
Expand All @@ -41,21 +44,30 @@ public Optional<String> getMessage() {
return Optional.ofNullable(message);
}

/**
* The stringified stack trace of the exception that caused this result
*/
public Optional<String> getStackTrace() {
return Optional.ofNullable(stackTrace);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Exception that = (Exception) o;
return
type.equals(that.type) &&
Objects.equals(message, that.message);
Objects.equals(message, that.message) &&
Objects.equals(stackTrace, that.stackTrace);
}

@Override
public int hashCode() {
return Objects.hash(
type,
message
message,
stackTrace
);
}

Expand All @@ -64,6 +76,7 @@ public String toString() {
return "Exception{" +
"type=" + type +
", message=" + message +
", stackTrace=" + stackTrace +
'}';
}
}
2 changes: 1 addition & 1 deletion java/src/main/java/io/cucumber/messages/Convertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private Convertor(){
}

public static Exception toMessage(Throwable t) {
return new Exception(t.getClass().getName(), t.getMessage());
return new Exception(t.getClass().getName(), t.getMessage(), null);
davidjgoss marked this conversation as resolved.
Show resolved Hide resolved
}

public static Timestamp toMessage(java.time.Instant instant) {
Expand Down
2 changes: 2 additions & 0 deletions javascript/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export class Exception {
type: string = ''

message?: string

stackTrace?: string
}

export class GherkinDocument {
Expand Down
4 changes: 4 additions & 0 deletions jsonschema/Exception.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"message": {
"type": "string",
"description": "The message of exception that caused this result. E.g. expected: \"a\" but was: \"b\""
},
"stackTrace": {
"type": "string",
"description": "The stringified stack trace of the exception that caused this result"
}
},
"type": "object"
Expand Down
1 change: 1 addition & 0 deletions messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ will only have one of its fields set, which indicates the payload of the message
| ----- | ---- | ----------- | ----------- |
| `type` | string | yes | |
| `message` | string | no | |
| `stackTrace` | string | no | |

## GherkinDocument

Expand Down
12 changes: 12 additions & 0 deletions perl/lib/Cucumber/Messages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ use Scalar::Util qw( blessed );
my %types = (
type => 'string',
message => 'string',
stack_trace => 'string',
);

# This is a work-around for the fact that Moo doesn't have introspection
Expand Down Expand Up @@ -580,6 +581,17 @@ has message =>
);


=head4 stack_trace

The stringified stack trace of the exception that caused this result

=cut

has stack_trace =>
(is => 'ro',
);


}

package Cucumber::Messages::GherkinDocument {
Expand Down
17 changes: 17 additions & 0 deletions php/src-generated/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function __construct(
* The message of exception that caused this result. E.g. expected: "a" but was: "b"
*/
public readonly ?string $message = null,

/**
* The stringified stack trace of the exception that caused this result
*/
public readonly ?string $stackTrace = null,
) {
}

Expand All @@ -47,10 +52,12 @@ public static function fromArray(array $arr): self
{
self::ensureType($arr);
self::ensureMessage($arr);
self::ensureStackTrace($arr);

return new self(
(string) $arr['type'],
isset($arr['message']) ? (string) $arr['message'] : null,
isset($arr['stackTrace']) ? (string) $arr['stackTrace'] : null,
);
}

Expand All @@ -76,4 +83,14 @@ private static function ensureMessage(array $arr): void
throw new SchemaViolationException('Property \'message\' was array');
}
}

/**
* @psalm-assert array{stackTrace?: string|int|bool} $arr
*/
private static function ensureStackTrace(array $arr): void
{
if (array_key_exists('stackTrace', $arr) && is_array($arr['stackTrace'])) {
throw new SchemaViolationException('Property \'stackTrace\' was array');
}
}
}
1 change: 1 addition & 0 deletions ruby/lib/cucumber/messages.deserializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def self.from_h(hash)
self.new(
type: hash[:type],
message: hash[:message],
stack_trace: hash[:stackTrace],
)
end
end
Expand Down
9 changes: 8 additions & 1 deletion ruby/lib/cucumber/messages.dtos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,19 @@ class Exception < ::Cucumber::Messages::Message
##
attr_reader :message

##
# The stringified stack trace of the exception that caused this result
##
attr_reader :stack_trace

def initialize(
type: '',
message: nil
message: nil,
stack_trace: nil
)
@type = type
@message = message
@stack_trace = stack_trace
end
end

Expand Down