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

[tcgc] deprecate isErrorOrChildOfError #381

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,7 @@
---
changeKind: deprecation
packages:
- "@azure-tools/typespec-client-generator-core"
---

deprecating isErrorOrChildOfError. Users should directly use isErrorModel from the standard TypeSpec library
4 changes: 4 additions & 0 deletions packages/typespec-client-generator-core/src/public-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ function buildNameFromContextPaths(context: TCGCContext, contextPath: ContextNod
return createName;
}

/**
*
* @deprecated This function is deprecated. You should use isErrorModel from the standard TypeSpec library
*/
export function isErrorOrChildOfError(context: TCGCContext, model: Model): boolean {
const errorDecorator = isErrorModel(context.program, model);
if (errorDecorator) return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getNamespaceFullName,
getVisibility,
ignoreDiagnostics,
isErrorModel,
isNeverType,
isNullType,
} from "@typespec/compiler";
Expand Down Expand Up @@ -104,7 +105,6 @@ import {
getGeneratedName,
getLibraryName,
getPropertyNames,
isErrorOrChildOfError,
} from "./public-utils.js";

import { UnionEnumVariant } from "../../typespec-azure-core/dist/src/helpers/union-enums.js";
Expand Down Expand Up @@ -529,7 +529,7 @@ export function getSdkModelWithDiagnostics(
apiVersions: getAvailableApiVersions(context, type),
isFormDataType:
isMultipartOperation(context, operation) && isOperationBodyType(context, type, operation),
isError: isErrorOrChildOfError(context, type),
isError: isErrorModel(context.program, type),
};
updateModelsMap(context, type, sdkType, operation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,7 @@ describe("typespec-client-generator-core: types", () => {
strictEqual(models[0].isError, true);
const rawModel = models[0].__raw!;
strictEqual(rawModel.kind, "Model");
// eslint-disable-next-line deprecation/deprecation
strictEqual(isErrorOrChildOfError(runner.context, rawModel), true);
});

Expand Down
Loading