Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ describe('useCopyIssueDetails', () => {
expect(result).toContain('## Plan');
});

it('includes the message when it differs from the title', () => {
const result = issueAndEventToMarkdown({
group: GroupFixture({title: 'TypeError'}),
event: EventFixture({...event, message: 'Connection to database timed out'}),
organization,
});

expect(result).toContain('## Message');
expect(result).toContain('Connection to database timed out');
});

it('omits the message when it is already part of the title', () => {
const result = issueAndEventToMarkdown({
group: GroupFixture({title: 'TypeError: connection failed'}),
event: EventFixture({...event, message: 'connection failed'}),
organization,
});

expect(result).not.toContain('## Message');
});

it('omits the message when it is empty', () => {
const result = issueAndEventToMarkdown({
group: GroupFixture({title: 'TypeError'}),
event: EventFixture({...event, message: ' '}),
organization,
});

expect(result).not.toContain('## Message');
});

it('includes tags when present in event', () => {
const eventWithTags = {
...event,
Expand Down Expand Up @@ -175,6 +206,64 @@ describe('useCopyIssueDetails', () => {
expect(result).toContain('**Type:** TypeError');
expect(result).toContain('**Value:** Cannot read property of undefined');
expect(result).toContain('#### Stacktrace');
// No mechanism on this exception, so no handled line.
expect(result).not.toContain('**Handled:**');
});

it('marks an unhandled exception', () => {
const eventWithUnhandled = EventFixture({
...event,
entries: [
{
type: EntryType.EXCEPTION,
data: {
values: [
{
type: 'TypeError',
value: 'boom',
mechanism: {type: 'onerror', handled: false},
},
],
},
},
],
});

const result = issueAndEventToMarkdown({
group,
event: eventWithUnhandled,
organization,
});

expect(result).toContain('**Handled:** No');
});

it('marks a handled exception', () => {
const eventWithHandled = EventFixture({
...event,
entries: [
{
type: EntryType.EXCEPTION,
data: {
values: [
{
type: 'ValueError',
value: 'caught',
mechanism: {type: 'generic', handled: true},
},
],
},
},
],
});

const result = issueAndEventToMarkdown({
group,
event: eventWithHandled,
organization,
});

expect(result).toContain('**Handled:** Yes');
});

it('includes thread stacktrace when activeThreadId matches', () => {
Expand Down
13 changes: 13 additions & 0 deletions static/app/views/issueDetails/hooks/useCopyIssueDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ function formatEventToMarkdown(event: Event, activeThreadId: number | undefined)
if (exception.type) {
markdownText += `**Type:** ${exception.type}\n`;
}
// Mirror Seer's `is_exception_handled`: an unhandled exception crashed
// the program, a handled one was caught. Only emit it when known.
const handled = exception.mechanism?.handled;
if (handled !== null && handled !== undefined) {
markdownText += `**Handled:** ${handled ? 'Yes' : 'No'}\n`;
}
if (exception.value) {
markdownText += `**Value:** ${exception.value}\n\n`;
}
Expand Down Expand Up @@ -272,6 +278,13 @@ export const issueAndEventToMarkdown = ({
markdownText += `**Date:** ${new Date(event.dateCreated).toLocaleString()}\n`;
}

// Mirror Seer: include the event message only when it adds something beyond
// the title, since for most errors the title already is the message.
const message = event?.message?.trim();
if (message && !group.title.includes(message)) {
markdownText += `\n## Message\n\n${message}\n`;
}

if (autofixData) {
const sections = getOrderedAutofixSections(autofixData);
const rootCauseSection = sections.find(isRootCauseSection);
Expand Down
Loading