def parseData()

in debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala [472:563]


    def parseData(arguments: JsonObject) =
      Option(arguments.getAsJsonPrimitive("data"))
        .toRight("missing 'data' field from launch request")
        .flatMap(path =>
          Either
            .catchNonFatal(Paths.get(path.getAsString))
            .leftMap(t => s"'data' field from launch request is not a valid path: $t")
            .ensureOr(path => s"data file at $path doesn't exist")(_.toFile().exists())
        )
        .toEitherNel

    // Parse the stopOnEntry field from the launch config
    // Defaults to true
    //
    // arguments: Launch config
    def parseStopOnEntry(arguments: JsonObject) =
      Option(arguments.getAsJsonPrimitive("stopOnEntry"))
        .map(_.getAsBoolean())
        .getOrElse(true)
        .asRight[String]
        .toEitherNel

    // Parse the infosetFormat field from the launch config
    // Defaults to "xml"
    //
    // arguments: Launch config
    def parseInfosetFormat(arguments: JsonObject) =
      Option(arguments.getAsJsonPrimitive("infosetFormat"))
        .map(_.getAsString())
        .getOrElse("xml")
        .asRight[String]
        .toEitherNel

    // Parse the infosetOutput object from the launch config
    //
    // infosetOutput: {
    //   type: '',
    //   path: ''
    // }
    //
    // Type must be 'none' | 'console' | 'file'
    // If type is 'file', there must be a 'path' field that contains a valid path
    //   for the resulting infoset to be written to
    // A case where the user expects a new directory to be created is not a valid path
    //   eg. /path/to/<existing>/<non-existing>/file.tdml
    //
    // arguments:   Launch config
    // requireFile: Whether or not the type field must be set to file. This is a requirement
    //              for the TDML generate operation. Returns an error if this boolean
    //              is set to True, and the type field is set to a value other than file
    def parseInfosetOutput(arguments: JsonObject, requireFile: Boolean = false) =
      Option(arguments.getAsJsonObject("infosetOutput")) match {
        case None => Right(LaunchArgs.InfosetOutput.Console).toEitherNel
        case Some(infosetOutput) =>
          Option(infosetOutput.getAsJsonPrimitive("type")) match {
            case None => Right(LaunchArgs.InfosetOutput.Console).toEitherNel
            case Some(typ) =>
              typ.getAsString() match {
                case "none" =>
                  if (requireFile)
                    Left("'type' field in 'infosetOutput' must be set to 'file'").toEitherNel
                  else
                    Right(LaunchArgs.InfosetOutput.None).toEitherNel
                case "console" =>
                  if (requireFile)
                    Left("'type' field in 'infosetOutput' must be set to 'file'").toEitherNel
                  else
                    Right(LaunchArgs.InfosetOutput.Console).toEitherNel
                case "file" =>
                  Option(infosetOutput.getAsJsonPrimitive("path"))
                    .toRight("missing 'infosetOutput.path' field from launch request")
                    .flatMap(path =>
                      Either
                        .catchNonFatal(LaunchArgs.InfosetOutput.File(Paths.get(path.getAsString)))
                        .leftMap(t => s"'infosetOutput.path' field from launch request is not a valid path: $t")
                        .ensureOr(file => s"can't write to infoset output file at ${file.path}") { f =>
                          val file = f.path.toFile
                          // If an empty string is passed in, it will be set to the workspace directory by default
                          // This is inside the Java code, so we have to make sure that the TDML file we
                          //   are working with is not a directory
                          !file
                            .isDirectory() && (file.canWrite || (!file.exists && file.getParentFile.canWrite))
                        }
                    )
                    .toEitherNel
                case invalidType =>
                  Left(
                    s"invalid 'infosetOutput.type': '$invalidType', must be 'none', 'console', or 'file'"
                  ).toEitherNel
              }
          }
      }