Taritsyn/DartSassHost

@Import extensionless file throws a System.UriFormatException

Closed this issue · 2 comments

Attempting to import a partial file that does not have an extension causes an error to be thrown by the DartSassHost code which is NOT handled with a SassException. At first I thought this might be a Dart Sass issue, but now it appears to be a DartSassHost bug:

Using a virtual filesystem that allows files without extensions and file structure like this:

  • /bootstrap5/scss/bootstrap.scss
    • @import "mixins/banner";
  • /bootstrap5/scss/mixins/_banner
    • ... contents of this file do not matter for this issue ...

Attempting to compile bootstrap.scss results in the following error message:

System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at DartSassHost.Helpers.PathHelpers.MakeRelativePath(String relativeTo, String path)
   at DartSassHost.Helpers.PathHelpers.PrettifyPath(String currentDirectory, String path)
   at DartSassHost.JsonConverters.CompilationResultConverter.ReadStackFrame(Utf8JsonReader& reader, String currentDirectory)
   at DartSassHost.JsonConverters.CompilationResultConverter.ReadStackFrames(Utf8JsonReader& reader, String currentDirectory)
   at DartSassHost.JsonConverters.CompilationResultConverter.ReadError(Utf8JsonReader& reader)
   at DartSassHost.JsonConverters.CompilationResultConverter.ReadFirstError(Utf8JsonReader& reader)
   at DartSassHost.JsonConverters.CompilationResultConverter.ReadResult(Utf8JsonReader& reader)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at DartSassHost.SassCompiler.InnerCompile(String content, Boolean indentedSyntax, String inputPath, String outputPath, String sourceMapPath, CompilationOptions options)
   at DartSassHost.SassCompiler.Compile(String content, String inputPath, String outputPath, String sourceMapPath, CompilationOptions options)
   at ... 

Aside from the fact that in most system having files without extensions is generally not a good idea (let's just say I don't have any control over that), this code seems to be supported by Dart Sass and can be compiled successfully using other tools (including the LibSassHost library).

Hello, Levi!

Show me the source code of the CustomVirtualFileManager class.

Hello, Levi!

It is quite possible that the error you describe has been fixed in version 1.0.0.