Sam build in Intelellij: 错误: JavaMavenWorkflow:MavenBuild - 'utf-8'编解码器无法解码位置 150889 中的字节0xbb:起始字节



我正在使用一个带有spring引导应用程序的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

我今天在我的机器上为用Maven构建的Java 11项目执行sam build时遇到了同样的问题。

我认为问题在于:

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

我在谷歌发现了一些点击,其他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 FilesAmazonAWSSAMCLIruntimelibsite-packagesaws_lambda_buildersworkflow.py", line 278, in run
action.execute()
File "C:Program FilesAmazonAWSSAMCLIruntimelibsite-packagesaws_lambda_buildersworkflowsjava_mavenactions.py", line 36, in execute
self.subprocess_maven.build(self.scratch_dir)
File "C:Program FilesAmazonAWSSAMCLIruntimelibsite-packagesaws_lambda_buildersworkflowsjava_mavenmaven.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 FilesAmazonAWSSAMCLIruntimelibsite-packagesaws_lambda_buildersworkflowsjava_mavenmaven.py

注意:在Windows上,如果SAM CLI安装在";程序文件">

对我来说,这是导致错误的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-编码

我将编辑保存到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:UsersjtoughAppDataLocalTemptmpi8or6ls5targetsurefire-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

最新更新