Skip to content

Commit

Permalink
Improve reusability forwarding errors further
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Aug 1, 2023
1 parent 02ef9f5 commit 82a97b2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,16 @@ asCompletelyLoweredElmApp entryPointClasses arguments =
Ok sourceDirs ->
let
sourceModules =
elmModulesDictFromAppFiles arguments.sourceFiles
arguments.sourceFiles
|> elmModulesDictFromAppFiles
|> Dict.toList
|> List.filterMap
(\( filePath, moduleResult ) ->
moduleResult
|> Result.toMaybe
|> Maybe.map (Tuple.pair filePath)
)
|> Dict.fromList

compilationInterfaceModuleDependencies : Dict.Dict String (List String)
compilationInterfaceModuleDependencies =
Expand Down Expand Up @@ -2554,36 +2563,33 @@ findModuleByName moduleName =
Dict.toList >> List.filter (Tuple.second >> .moduleName >> (==) moduleName) >> List.head


elmModulesDictFromAppFiles : AppFiles -> Dict.Dict (List String) SourceParsedElmModule
elmModulesDictFromAppFiles : AppFiles -> Dict.Dict (List String) (Result String SourceParsedElmModule)
elmModulesDictFromAppFiles =
Dict.toList
>> List.filter
(Tuple.first
>> List.reverse
>> List.head
>> Maybe.map (String.toLower >> String.endsWith ".elm")
>> Maybe.withDefault False
)
>> List.filterMap
(\( filePath, fileContent ) ->
stringFromFileContent fileContent
|> Maybe.andThen
Dict.filter
(List.reverse
>> List.head
>> Maybe.map (String.toLower >> String.endsWith ".elm")
>> Maybe.withDefault False
>> always
)
>> Dict.map
(\_ ->
stringFromFileContent
>> Maybe.map Ok
>> Maybe.withDefault (Err "Failed to decode file content as string")
>> Result.andThen
(\fileContentAsString ->
case parseElmModuleText fileContentAsString of
Err _ ->
Nothing

Ok elmFile ->
Just
( filePath
, { fileText = fileContentAsString
, parsedSyntax = elmFile
, moduleName = Elm.Syntax.Module.moduleName (Elm.Syntax.Node.value elmFile.moduleDefinition)
}
)
parseElmModuleText fileContentAsString
|> Result.mapError Parser.deadEndsToString
|> Result.map
(\parsedSyntax ->
{ fileText = fileContentAsString
, parsedSyntax = parsedSyntax
, moduleName = Elm.Syntax.Module.moduleName (Elm.Syntax.Node.value parsedSyntax.moduleDefinition)
}
)
)
)
>> Dict.fromList


elmModulesDictFromModuleTexts : (List String -> List String) -> List String -> Result String (Dict.Dict (List String) SourceParsedElmModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ subscriptions _ =
]
|> Dict.fromList
|> CompileElmApp.elmModulesDictFromAppFiles
|> Dict.toList
|> List.filterMap
(\( filePath, moduleResult ) ->
moduleResult
|> Result.toMaybe
|> Maybe.map (Tuple.pair filePath)
)
|> Dict.fromList
in
CompileBackendApp.parseAppStateElmTypeAndDependenciesRecursively
rootFunctionDeclaration
Expand Down
2 changes: 1 addition & 1 deletion implement/elm-time/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ElmTime;

public class Program
{
public static string AppVersionId => "2023-07-31";
public static string AppVersionId => "2023-08-01";

private static int AdminInterfaceDefaultPort => 4000;

Expand Down
4 changes: 2 additions & 2 deletions implement/elm-time/elm-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmTime</RootNamespace>
<AssemblyName>elm-time</AssemblyName>
<AssemblyVersion>2023.0731.0.0</AssemblyVersion>
<FileVersion>2023.0731.0.0</FileVersion>
<AssemblyVersion>2023.0801.0.0</AssemblyVersion>
<FileVersion>2023.0801.0.0</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit 82a97b2

Please sign in to comment.