1010import com .fasterxml .jackson .databind .node .ObjectNode ;
1111import com .github .mustachejava .DefaultMustacheFactory ;
1212import com .github .mustachejava .Mustache ;
13+ import org .apache .logging .log4j .Logger ;
14+ import org .apache .logging .log4j .LogManager ;
1315
1416import java .io .File ;
1517import java .io .FileOutputStream ;
3234
3335public final class Codegen {
3436
37+ private static Logger logger = LogManager .getLogger (Codegen .class );
38+
3539 private final ObjectMapper mapper ;
3640 private final ObjectNode definitions ;
3741 private final Config config ;
@@ -189,6 +193,7 @@ public void generate() throws Exception {
189193 config .getSettings ().getRegions ().stream ()
190194 .map (region -> {
191195 try {
196+ logger .debug ("Loading specification for {}" , region );
192197 return new Object [] {
193198 region ,
194199 loadSpecification (region ),
@@ -197,17 +202,21 @@ public void generate() throws Exception {
197202 };
198203 }
199204 catch (Exception e ) {
205+ logger .fatal (String .format ("Loading specification for %s failed" , region ), e );
200206 throw new RuntimeException (e );
201207 }
202208 })
203209 .forEach (result -> {
210+ String region = (String )result [0 ];
211+ logger .debug ("Starting generation for {} specification" , region );
204212 CfnSpecification spec = (CfnSpecification ) result [1 ];
205213 Map <String , File > locations = (Map <String , File >) result [2 ];
206214 Map <String , ObjectNode > defns = (Map <String , ObjectNode >) result [3 ];
207215 try {
208216 generate (spec , locations , defns );
209217 }
210218 catch (Exception e ) {
219+ logger .fatal (String .format ("Generation for %s specification failed" , region ), e );
211220 throw new RuntimeException (e );
212221 }
213222 });
@@ -227,12 +236,26 @@ private void generate(CfnSpecification specification,
227236
228237 Map <List <String >, ObjectNode > definitions = new LinkedHashMap <>(sorted .size ());
229238 for (final String name : sorted ) {
230- ResourceType type = resources .get (name );
231- String defnName = name .replace ("::" , "_" );
232- resDefns .add (defnName );
233- ObjectNode typeDefn = mapper .createObjectNode ();
234- handleType (typeDefn , defnName , name , type , true , propertyNames );
235- definitions .put (Arrays .asList (name , defnName ), typeDefn );
239+ ResourceType type = null ;
240+ try {
241+ type = resources .get (name );
242+ String defnName = name .replace ("::" , "_" );
243+ resDefns .add (defnName );
244+ ObjectNode typeDefn = mapper .createObjectNode ();
245+ handleType (typeDefn , defnName , name , type , true , propertyNames );
246+ definitions .put (Arrays .asList (name , defnName ), typeDefn );
247+ logger .debug ("Processed type {}" , name );
248+ }
249+ catch (Exception e )
250+ {
251+ // ignore and emit warning for malformed types in the spec
252+ if (type != null ) {
253+ logger .error ("An error occurred processing type {}" , name );
254+ }
255+ else {
256+ throw e ;
257+ }
258+ }
236259 }
237260 addToPerGroupRoots (definitions , groupSpecDefinitions );
238261
0 commit comments