fossas / fossa-cli

Fast, portable and reliable dependency analysis for any codebase. Supports license & vulnerability scanning for large monoliths. Language-agnostic; integrates with 20+ build systems.
https://fossa.com
Other
1.26k stars 173 forks source link

[BUG] In debug bundle, many extra backslashes appear in Windows paths when a command fails #1408

Closed ryanlink closed 5 months ago

ryanlink commented 5 months ago

Describe the bug When using --debug to generate output from fossa analyze to troubleshoot a command failure in the build process on a Windows machine, the output contains many redundant backslashes, presumably as escape chars:

Attempted to run the command 'C:\\\\\\\\Program Files\\\\\\\\apache-maven-3.9.6\\\\\\\\bin\\\\\\\\mvn -v'\\\\n inside the working directory 'C:\\\\\\\\FOSSA\\\\\\\\pfmService\\\\\\\\access-center\\\\\\\\',\\\\n but failed, because the command exited with code '1'.\\\\n\\\\n Often, this kind of error is caused by the project not being ready to build;\\\\n please ensure that the project at 'C:\\\\\\\\FOSSA\\\\\\\\pfmService\\\\\\\\access-center\\\\\\\\'\\\\n builds successfully before running fossa

To Reproduce Steps to reproduce the behavior:

  1. Run fossa analyze ...
  2. See error

Expected behavior This error should not contain extraneous backslashes.

Debug bundle Please run fossa with the --debug flag and attach the resulting fossa.debug.json.gz file here.

Additional context I asked ChatGPT to analyze the code in https://github.com/fossas/fossa-cli/blob/master/src/Effect/Exec.hs and explain the backslashes. Here's the response:

It seems that the extra backslashes are appearing in the error message because of the way the paths are constructed and processed in the code. Let's break down the possible reasons:

  1. Path Construction: In Haskell's Path module, paths are constructed using a type-safe representation, which ensures that file paths are correctly formed. However, when converting these paths to strings for display, the conversion process may introduce additional escape characters if not handled properly.

  2. Text Encoding: When converting between Text and String types, especially with file paths, encoding issues may arise, leading to unexpected characters or escape sequences being introduced.

  3. Text Interpolation: In the error message generation, if interpolation is done incorrectly or if there are inconsistencies in handling string literals and interpolated values, extra backslashes might appear.

To address this issue, you should ensure that:

  • When constructing paths from Path types to strings, you're using appropriate functions provided by the Path module to convert them without introducing escape characters unnecessarily.

  • When interpolating paths into strings or error messages, ensure that the escaping is handled correctly. This might involve using functions like toFilePath from the Path module or escaping special characters explicitly if needed.

  • Double-check any custom text processing or interpolation functions to ensure they're handling paths and strings correctly, without inadvertently adding extra backslashes.

By carefully reviewing the code where paths are constructed, converted, and interpolated, you should be able to identify and resolve the issue causing the extra backslashes in the error messages.

github-actions[bot] commented 5 months ago

Thank you @ryanlink for creating this issue. If this is in regards to a defect, product question or feature request: you should use our support portal at https://support.fossa.com to file a request, as you would receive more immediate support.

ryanlink commented 5 months ago

Debug bundle fossa.debug (25).json.gz

ryanlink commented 5 months ago

Note that these redundant backslashes do not occur in fossa-analyze-scan-summary.txt:

  Warn: Command: `mvn` not suitable
  Running with args: `-v` resulted in a non-zero exit code

    Warn: Command execution failed
      Attempted to run the command 'mvn -v'
      inside the working directory 'D:\AINow\OTA1_3_22\backend\ainow-cloud-service\',
      but failed, because the command exited with code '1'.

      Often, this kind of error is caused by the project not being ready to build;
      please ensure that the project at 'D:\AINow\OTA1_3_22\backend\ainow-cloud-service\'
      builds successfully before running fossa.

      The logs for the command are listed below.
      They will likely provide guidance on how to resolve this error.
      Command did not write a standard log.

      Command error log:
        mvn: startProcess: does not exist (No such file or directory)
    Support: If you believe this to be a defect, please report a bug to FOSSA support at https://support.fossa.com
ryanlink commented 5 months ago

Closing, filed as internal Jira ticket https://fossa.atlassian.net/browse/ANE-1638