-
Notifications
You must be signed in to change notification settings - Fork 28
Extract error codes into errorHelper.ts for agents-activity and agents-hosting packages #787
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
Open
Copilot
wants to merge
13
commits into
main
Choose a base branch
from
copilot/extract-error-codes-agents-activity-hosting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dfa4446
Initial plan
Copilot c459d1e
Add errorHelper for agents-activity package with error codes -110000 …
Copilot 3c9d005
Add errorHelper for agents-hosting package with initial refactoring
Copilot bdeb5c5
Continue refactoring agents-hosting: activityHandler and cloudAdapter
Copilot 8178e80
Continue refactoring agents-hosting: oauth, transcript, connector-cli…
Copilot 94ebbc2
Complete refactoring of remaining 19 files in agents-hosting package
Copilot 23f4fea
Fix type errors and revert non-standard error messages in agentApplic…
Copilot 1d9828e
Fix linting errors: consolidate duplicate imports and use property sh…
Copilot 227931e
Fix authorization tests to handle new error message format with error…
Copilot 0dd6bd3
Fix jwt-middleware and turnContext tests to handle new error format
Copilot df4d7db
Fix all remaining test failures - update cloudAdapter and fileTranscr…
Copilot 0253412
Update error code range test to use broader range -110999 to -110000
Copilot 7375f17
Update packages/agents-hosting/src/cloudAdapter.ts
cleemullins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { AgentErrorDefinition } from './exceptionHelper' | ||
|
|
||
| /** | ||
| * Error definitions for the Activity system. | ||
| * This contains localized error codes for the Activity subsystem of the AgentSDK. | ||
| * | ||
| * Each error definition includes an error code (starting from -110000), a description, and a help link | ||
| * pointing to an AKA link to get help for the given error. | ||
| * | ||
| * Usage example: | ||
| * ``` | ||
| * throw ExceptionHelper.generateException( | ||
| * Error, | ||
| * Errors.InvalidActivityTypeUndefined | ||
| * ); | ||
| * ``` | ||
| */ | ||
| export const Errors: { [key: string]: AgentErrorDefinition } = { | ||
| /** | ||
| * Error thrown when ActivityType is undefined. | ||
| */ | ||
| InvalidActivityTypeUndefined: { | ||
| code: -110000, | ||
| description: 'Invalid ActivityType: undefined', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when ActivityType is null. | ||
| */ | ||
| InvalidActivityTypeNull: { | ||
| code: -110001, | ||
| description: 'Invalid ActivityType: null', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when ActivityType is an empty string. | ||
| */ | ||
| InvalidActivityTypeEmptyString: { | ||
| code: -110002, | ||
| description: 'Invalid ActivityType: empty string', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when channelId contains a subChannel but no main channel. | ||
| */ | ||
| InvalidChannelIdSubChannelOnly: { | ||
| code: -110003, | ||
| description: 'Invalid channelId {channelId}. Found subChannel but no main channel.', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when attempting to set subChannel before setting primary channel. | ||
| */ | ||
| PrimaryChannelNotSet: { | ||
| code: -110004, | ||
| description: 'Primary channel must be set before setting subChannel', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when Activity Recipient is undefined. | ||
| */ | ||
| ActivityRecipientUndefined: { | ||
| code: -110005, | ||
| description: 'Activity Recipient undefined', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when Activity Conversation is undefined. | ||
| */ | ||
| ActivityConversationUndefined: { | ||
| code: -110006, | ||
| description: 'Activity Conversation undefined', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| }, | ||
|
|
||
| /** | ||
| * Error thrown when Activity ChannelId is undefined. | ||
| */ | ||
| ActivityChannelIdUndefined: { | ||
| code: -110007, | ||
| description: 'Activity ChannelId undefined', | ||
| helplink: 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import assert from 'assert' | ||
| import { describe, it } from 'node:test' | ||
| import { AgentErrorDefinition } from '../src/exceptionHelper' | ||
| import { Errors } from '../src/errorHelper' | ||
|
|
||
| describe('Activity Errors tests', () => { | ||
| it('should have InvalidActivityTypeUndefined error definition', () => { | ||
| const error = Errors.InvalidActivityTypeUndefined | ||
|
|
||
| assert.strictEqual(error.code, -110000) | ||
| assert.strictEqual(error.description, 'Invalid ActivityType: undefined') | ||
| assert.strictEqual(error.helplink, 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}') | ||
| }) | ||
|
|
||
| it('should have InvalidActivityTypeNull error definition', () => { | ||
| const error = Errors.InvalidActivityTypeNull | ||
|
|
||
| assert.strictEqual(error.code, -110001) | ||
| assert.strictEqual(error.description, 'Invalid ActivityType: null') | ||
| assert.strictEqual(error.helplink, 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}') | ||
| }) | ||
|
|
||
| it('should have InvalidActivityTypeEmptyString error definition', () => { | ||
| const error = Errors.InvalidActivityTypeEmptyString | ||
|
|
||
| assert.strictEqual(error.code, -110002) | ||
| assert.strictEqual(error.description, 'Invalid ActivityType: empty string') | ||
| assert.strictEqual(error.helplink, 'https://aka.ms/M365AgentsErrorCodes/#{errorCode}') | ||
| }) | ||
|
|
||
| it('should have all error codes in the correct range', () => { | ||
| const errorDefinitions = Object.values(Errors).filter( | ||
| val => val && typeof val === 'object' && 'code' in val && 'description' in val && 'helplink' in val | ||
| ) as AgentErrorDefinition[] | ||
|
|
||
| // All error codes should be negative and in the range -110000 to -110007 | ||
cleemullins marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| errorDefinitions.forEach(errorDef => { | ||
| assert.ok(errorDef.code < 0, `Error code ${errorDef.code} should be negative`) | ||
| assert.ok(errorDef.code >= -110007, `Error code ${errorDef.code} should be >= -110007`) | ||
| assert.ok(errorDef.code <= -110000, `Error code ${errorDef.code} should be <= -110000`) | ||
| }) | ||
| }) | ||
|
|
||
| it('should have unique error codes', () => { | ||
| const errorDefinitions = Object.values(Errors).filter( | ||
| val => val && typeof val === 'object' && 'code' in val && 'description' in val && 'helplink' in val | ||
| ) as AgentErrorDefinition[] | ||
|
|
||
| const codes = errorDefinitions.map(e => e.code) | ||
| const uniqueCodes = new Set(codes) | ||
|
|
||
| assert.strictEqual(codes.length, uniqueCodes.size, 'All error codes should be unique') | ||
| }) | ||
|
|
||
| it('should have help links with tokenized format', () => { | ||
| const errorDefinitions = Object.values(Errors).filter( | ||
| val => val && typeof val === 'object' && 'code' in val && 'description' in val && 'helplink' in val | ||
| ) as AgentErrorDefinition[] | ||
|
|
||
| errorDefinitions.forEach(errorDef => { | ||
| assert.ok( | ||
| errorDef.helplink.includes('{errorCode}'), | ||
| `Help link should contain {errorCode} token: ${errorDef.helplink}` | ||
| ) | ||
| assert.ok( | ||
| errorDef.helplink.startsWith('https://aka.ms/M365AgentsErrorCodes/#'), | ||
| `Help link should start with correct URL: ${errorDef.helplink}` | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| it('should have non-empty descriptions', () => { | ||
| const errorDefinitions = Object.values(Errors).filter( | ||
| val => val && typeof val === 'object' && 'code' in val && 'description' in val && 'helplink' in val | ||
| ) as AgentErrorDefinition[] | ||
|
|
||
| errorDefinitions.forEach(errorDef => { | ||
| assert.ok(errorDef.description.length > 0, 'Description should not be empty') | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.