Skip to content

Commit f57a8d3

Browse files
Roman Castellarinfacebook-github-bot
Roman Castellarin
authored andcommitted
Show enclosing schema on schema name resolution error
Summary: If a schema name is unknown, glean throws an error and prints the wrong name, but not where it occurred > gen-schema: unknown schema: hs.2 This diff fixes that Reviewed By: jjuliamolin Differential Revision: D75794770 fbshipit-source-id: c394286cd70f8c325625d584619b07f9d6f426fe
1 parent 72e6c6e commit f57a8d3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

glean/hs/Glean/Schema/Resolve.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,20 @@ resolveSchemaRefs SourceSchemas{..} = do
217217
where
218218
unknown = throwError $ "unknown schema: " <> showRef ref
219219

220-
resolveDecl (SourceImport r s) = SourceImport <$> schemaByName r <*> pure s
221-
resolveDecl decl = return decl
220+
schemaByNameWithNamespace parentSchema ref =
221+
let message e = e <> " within schema: " <> showRef parentSchema
222+
in withExcept message (schemaByName ref)
223+
224+
resolveDecl parentSchema (SourceImport r s) =
225+
SourceImport <$> schemaByNameWithNamespace parentSchema r <*> pure s
226+
resolveDecl _ decl = return decl
222227

223228
resolveEvolve (SourceEvolves l n o) =
224229
SourceEvolves l <$> schemaByName n <*> schemaByName o
225230

226231
resolveSchema SourceSchema{..} = do
227-
inherits <- mapM schemaByName schemaInherits
228-
decls <- mapM resolveDecl schemaDecls
232+
inherits <- mapM (schemaByNameWithNamespace schemaName) schemaInherits
233+
decls <- mapM (resolveDecl schemaName) schemaDecls
229234
return SourceSchema
230235
{ schemaName = schemaName
231236
, schemaInherits = inherits

0 commit comments

Comments
 (0)