Sam 在 intellij 中构建:错误:JavaMavenWorkflow:MavenBuild - 'utf-8' 编解码器无法解码位置 150889 中的字节 0xbb:无效的起始字节

2024-05-09

我正在使用带有 Spring Boot 应用程序的 aws 无服务器架构。当我在 intellij 中使用 sam build 构建项目时,出现以下错误。

Building codeuri: . runtime: java11 metadata: {} functions: ['MedisproutApiFunction']
Running JavaMavenWorkflow:CopySource
Running JavaMavenWorkflow:MavenBuild

Build Failed
Error: JavaMavenWorkflow:MavenBuild - 'utf-8' codec can't decode byte 0xbb in position 150889: invalid start byte

它没有显示任何其他错误详细信息。如果我删除新进行的代码更改(即使它没有任何编码代码),则不会出现此错误。请帮我解决这个问题。

已经检查过此链接,但没有找到答案。

通过intellij插件将Lambda更新到AWS https://stackoverflow.com/questions/55818025/updating-lambda-to-aws-through-intellij-plugin


我今天在尝试做一个时遇到了同样的问题sam build在我的机器上使用 Maven 构建的 Java 11 项目。

我相信问题是这样的:

  • 当 Maven 构建失败时,Maven 输出一些不是有效 UTF-8 的文本。这发生在我身上,因为单元测试失败了。
  • SAM CLI 尝试捕获并修剪某些 Python 代码中的 Maven 输出,然后将其输出到控制台。当 Maven 输出不是干净的 UTF-8 文本时,这种情况就会崩溃。
  • 我们只能看到由无效的 UTF-8 文本引起的 Python 代码错误。 Maven 输出丢失。

我在 Google 中发现了一些其他 SAM 用户遇到类似问题的点击。不幸的是,解决方法涉及破坏作为 SAM CLI 的一部分安装的 Python 源代码。我不想这样做,但截至今天我还没有找到更干净的解决方案.

解决方法步骤:

使用以下命令在调试模式下执行 SAM 构建:

sam build --debug

在显示错误之前,您将看到 SAM 正在执行的操作的更多详细信息。

当构建失败时,记下发生错误的 Python 文件和行号。对我来说,它看起来像这样:

2021-11-19 09:41:30,430 | JavaMavenWorkflow:MavenBuild raised unhandled exception
Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflow.py", line 278, in run
    action.execute()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\actions.py", line 36, in execute
    self.subprocess_maven.build(self.scratch_dir)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\maven.py", line 31, in build
    LOG.debug("Maven logs: %s", stdout.decode("utf8").strip())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 3795: invalid start byte

找到有问题的 Python 文件并在文本编辑器中打开它。对我来说,该文件是:

C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\maven.py

注意:在 Windows 上,如果 SAM CLI 安装在“Program Files”下,则您需要以管理员身份执行此步骤。

对我来说,这是错误来源的 Python 函数:

def build(self, scratch_dir):
    args = ["clean", "install"]
    ret_code, stdout, _ = self._run(args, scratch_dir)

    LOG.debug("Maven logs: %s", stdout.decode("utf8").strip())

    if ret_code != 0:
        raise MavenExecutionError(message=stdout.decode("utf8").strip())

编辑代码并将“utf8”更改为不同的字符集代码。这对我有用:

def build(self, scratch_dir):
    args = ["clean", "install"]
    ret_code, stdout, _ = self._run(args, scratch_dir)

    LOG.debug("Maven logs: %s", stdout.decode("iso8859_2").strip())

    if ret_code != 0:
        raise MavenExecutionError(message=stdout.decode("iso8859_2").strip())

以下是 Python 编码的官方列表,以防您需要在自己的计算机上尝试不同的编码:

https://docs.python.org/3/library/codecs.html#standard-encodings https://docs.python.org/3/library/codecs.html#standard-encodings

我将编辑保存到 Python 文件中,然后运行sam build再次。这次我得到了 Maven 的正常输出。

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   DataFileEntryTest.unmarshallJsonSampleFileWithUnknownProperties:57 Unexpected exception type thrown ==> expected: <com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException> but was: <java.io.FileNotFoundException>
[ERROR] Errors:
[ERROR]   DataFileEntryTest.unmarshallJsonSampleFileWithMissingProperties:49 ť FileNotFound
[ERROR]   DataFileEntryTest.unmarshallValidJsonSampleFile:33 ť FileNotFound ..\test-data...
[INFO]
[ERROR] Tests run: 4, Failures: 1, Errors: 2, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.979 s
[INFO] Finished at: 2021-11-19T09:48:55-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project hello-sam: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\jtough\AppData\Local\Temp\tmpi8or6ls5\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Sam 在 intellij 中构建:错误:JavaMavenWorkflow:MavenBuild - 'utf-8' 编解码器无法解码位置 150889 中的字节 0xbb:无效的起始字节 的相关文章

随机推荐