2828import software .amazon .awssdk .codegen .model .service .Member ;
2929import software .amazon .awssdk .codegen .model .service .ServiceModel ;
3030import software .amazon .awssdk .codegen .model .service .Shape ;
31+ import software .amazon .awssdk .codegen .validation .ModelInvalidException ;
32+ import software .amazon .awssdk .codegen .validation .ValidationEntry ;
33+ import software .amazon .awssdk .codegen .validation .ValidationErrorId ;
34+ import software .amazon .awssdk .codegen .validation .ValidationErrorSeverity ;
3135
3236/**
3337 * Processor for eventstreams with shared events. This Processor does two things: 1. Apply the duplicateAndRenameSharedEvents
@@ -60,28 +64,34 @@ public void preprocess(ServiceModel serviceModel) {
6064 Member eventMemberToModify = eventStreamMembers .get (eventEntry .getKey ());
6165
6266 if (eventMemberToModify == null ) {
63- throw new IllegalStateException (
67+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
68+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
69+ ValidationErrorSeverity .DANGER ,
6470 String .format ("Cannot find event member [%s] in the eventstream [%s] when processing "
6571 + "customization config duplicateAndRenameSharedEvents.%s" ,
66- eventEntry .getKey (), eventStreamName , eventStreamName ));
72+ eventEntry .getKey (), eventStreamName , eventStreamName ))) ;
6773 }
6874
6975 String shapeToDuplicate = eventMemberToModify .getShape ();
7076 Shape eventMemberShape = serviceModel .getShape (shapeToDuplicate );
7177
7278 if (eventMemberShape == null || !eventMemberShape .isEvent ()) {
73- throw new IllegalStateException (
79+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
80+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
81+ ValidationErrorSeverity .DANGER ,
7482 String .format ("Error: [%s] must be an Event shape when processing "
7583 + "customization config duplicateAndRenameSharedEvents.%s" ,
76- eventEntry .getKey (), eventStreamName ));
84+ eventEntry .getKey (), eventStreamName ))) ;
7785 }
7886
7987 String newShapeName = eventEntry .getValue ();
8088 if (serviceModel .getShapes ().containsKey (newShapeName )) {
81- throw new IllegalStateException (
89+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
90+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
91+ ValidationErrorSeverity .DANGER ,
8292 String .format ("Error: [%s] is already in the model when processing "
8393 + "customization config duplicateAndRenameSharedEvents.%s" ,
84- newShapeName , eventStreamName ));
94+ newShapeName , eventStreamName ))) ;
8595 }
8696 serviceModel .getShapes ().put (newShapeName , duplicateShape (eventMemberShape ));
8797 eventMemberToModify .setShape (newShapeName );
@@ -105,14 +115,18 @@ private Shape duplicateShape(Shape shape) {
105115
106116 private static void validateIsEventStream (Shape shape , String name ) {
107117 if (shape == null ) {
108- throw new IllegalStateException (
118+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
119+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
120+ ValidationErrorSeverity .DANGER ,
109121 String .format ("Cannot find eventstream shape [%s] in the model when processing "
110- + "customization config duplicateAndRenameSharedEvents.%s" , name , name ));
122+ + "customization config duplicateAndRenameSharedEvents.%s" , name , name ))) ;
111123 }
112124 if (!shape .isEventstream ()) {
113- throw new IllegalStateException (
125+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
126+ ValidationErrorId .INVALID_CODEGEN_CUSTOMIZATION ,
127+ ValidationErrorSeverity .DANGER ,
114128 String .format ("Error: [%s] must be an EventStream when processing "
115- + "customization config duplicateAndRenameSharedEvents.%s" , name , name ));
129+ + "customization config duplicateAndRenameSharedEvents.%s" , name , name ))) ;
116130 }
117131 }
118132
@@ -129,10 +143,13 @@ public void postprocess(IntermediateModel intermediateModel) {
129143 if (memberShape != null && memberShape .isEvent ()) {
130144 if (seenEvents .containsKey (memberShape .getShapeName ())
131145 && !seenEvents .get (memberShape .getShapeName ()).equals (shapeModel .getShapeName ())) {
132- throw new IllegalStateException (
146+ throw ModelInvalidException .fromEntry (ValidationEntry .create (
147+ ValidationErrorId .SHARED_EVENTSTREAM_EVENT ,
148+ ValidationErrorSeverity .DANGER ,
133149 String .format ("Event shape `%s` is shared between multiple EventStreams. Apply the "
134150 + "duplicateAndRenameSharedEvents customization to resolve the issue." ,
135- memberShape .getShapeName ()));
151+ memberShape .getShapeName ())
152+ ));
136153 }
137154 seenEvents .put (memberShape .getShapeName (), shapeModel .getShapeName ());
138155 }
0 commit comments