LightDye
LightDye

Reputation: 1254

F4 IDE gives "Invalid Uri scheme for local file" when running Fantom app

I started a very simple project using Xored's F4 IDE for Fantom. The first few times I ran it there was no error, but I started adding dependencies (fanbatis) and at some point the error below starting showing up every time I run a test or a dummy Hello World app.

[23:44:18 22-Nov-13] [err] [pathenv] Cannot parse path: C:\dev\f4workspace\auth\bin\fan
  sys::ArgErr: Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
    fan.sys.LocalFile.uriToFile (LocalFile.java:64)
    fan.sys.File.make (File.java:26)
    util::PathEnv.parsePath (PathEnv.fan:47)
    fan.sys.List.each (List.java:555)
    util::PathEnv.parsePath (PathEnv.fan:43)
    util::PathEnv.make$ (PathEnv.fan:22)
    util::PathEnv.make (PathEnv.fan:20)
    java.lang.reflect.Method.invoke (Unknown)
    fan.sys.Method.invoke (Method.java:559)
    fan.sys.Method$MethodFunc.callList (Method.java:198)
    fan.sys.Type.make (Type.java:246)
    fan.sys.ClassType.make (ClassType.java:110)
    fan.sys.Type.make (Type.java:236)
    fan.sys.Sys.initEnv (Sys.java:447)
    fan.sys.Sys. (Sys.java:224)
    fanx.tools.Fan.execute (Fan.java:28)
    fanx.tools.Fan.run (Fan.java:298)
    fanx.tools.Fan.main (Fan.java:336)
Hello, World!

It is more a nuisance at the moment because the tests and the dummy app still run. I created another project, copying all the source code adding class by class and testing after each change and the error never occurred. Any ideas please?

Upvotes: 1

Views: 612

Answers (2)

Ivan Inozemtsev
Ivan Inozemtsev

Reputation: 21

That's an interesting issue!

tl/dr: you have an empty project 'auth' in your workspace, either create some dummy class inside it or go to Run -> Run configurations, find your launch config and uncheck project without sources on 'Projects' tab.

In order to keep your Fantom installation clean from projects in a workspace, F4 puts built pods into project/bin/fan/lib/fan. When F4 launches projects from workspace, it uses PathEnv and builds FAN_ENV_PATH by joining paths to Fantom installation and bin/ folders in projects in workspace.

When Fantom runtime analyzes FAN_ENV_PATH, at first it interprets a path as native OS path, but if dir does not exist, it attempts to interpret it as file URI, here's relevant part of PathEnv source:

path.split(File.pathSep[0]).each |item|
{
  if (item.isEmpty) return
  dir := File.os(item).normalize
  if (!dir.exists) dir = File(item.toUri.plusSlash, false).normalize
  if (!dir.exists) { log.warn("Dir not found: $dir"); return }

The problem code is item.toUri – On Mac OS X and Linux this is parsed as an URI without scheme with path only, so if directory does not exist, this code just prints a warning in a console.

But on Windows, because of disk name in path, disk name is interpreted as scheme:

fansh> "C:\\Users".toUri { echo(path); echo(scheme) }
[\Users]
c
fansh> "/Users".toUri { echo(path); echo(scheme) }
[Users]
null

And then File constructor fails, because expects either 'file' scheme, or null scheme:

public static java.io.File uriToFile(Uri uri)
{
  if (uri.scheme() != null && !uri.scheme().equals("file"))
    throw ArgErr.make("Invalid Uri scheme for local file: " + uri);
  return new java.io.File(uriToPath(uri));
}

I've created an issue here, so that F4 would automatically skip empty projects when building FAN_ENV_PATH – https://github.com/xored/f4/issues/25.

Upvotes: 2

LightDye
LightDye

Reputation: 1254

I thought the problem had something to do with the forward slash at the end of path as shown in this line of the error message

Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/

However, I found that such path didn't exist. I manually created both the bin and the fan folders and the error disappeared. To be honest I don't really know why F4 needs and checks for that folder because so far it hasn't written any file in it.

Upvotes: 0

Related Questions