@@ -14,6 +14,7 @@ import * as utils from '../utils/utils.js';
1414import * as tcgc from '@azure-tools/typespec-client-generator-core' ;
1515import * as rust from '../codemodel/index.js' ;
1616import { FinalStateValue } from "@azure-tools/typespec-azure-core" ;
17+ import { EmitContext , NoTarget } from "@typespec/compiler" ;
1718
1819/** ErrorCode defines the types of adapter errors */
1920export type ErrorCode =
@@ -114,8 +115,8 @@ export class Adapter {
114115 }
115116
116117 /** performs all the steps to convert tcgc to a crate */
117- tcgcToCrate ( ) : rust . Crate {
118- this . adaptTypes ( ) ;
118+ tcgcToCrate ( context : EmitContext < RustEmitterOptions > ) : rust . Crate {
119+ this . adaptTypes ( context ) ;
119120 this . adaptClients ( ) ;
120121
121122 // marker models don't require serde so exclude them from the check
@@ -146,10 +147,17 @@ export class Adapter {
146147 }
147148
148149 /** converts all tcgc types to their Rust type equivalent */
149- private adaptTypes ( ) : void {
150+ private adaptTypes ( context : EmitContext < RustEmitterOptions > ) : void {
150151 for ( const sdkUnion of this . ctx . sdkPackage . unions . filter ( u => u . kind === 'union' ) ) {
151152 if ( ! sdkUnion . discriminatedOptions ) {
152- throw new AdapterError ( 'UnsupportedTsp' , 'non-discriminated unions are not supported' , sdkUnion . __raw ?. node ) ;
153+ // When https://github.com/microsoft/typespec/issues/9749 is fixed, we can return to throwing an exception here.
154+ context . program . reportDiagnostic ( {
155+ code : 'UnsupportedTsp' ,
156+ severity : 'warning' ,
157+ message : `Non-discriminated unions ('${ sdkUnion . name } ') are not supported. No type will be generated.` ,
158+ target : NoTarget ,
159+ } )
160+ continue ;
153161 }
154162 const rustUnion = this . getDiscriminatedUnion ( sdkUnion ) ;
155163 this . crate . unions . push ( rustUnion ) ;
0 commit comments