Repository: flutter
Issue: [vector_graphics] build: Occasionaly fails to rename vector file after transforming during build
Labels: package,p: vector_graphics

_Imported from https://github.com/dnfield/vector_graphics/issues/252_

Original report by @ZiyadF296 on Aug 8, 2024

When building an app, while transforming assets, the following error gets dumped (built with verbose):

<details>
<summary>Error dump</summary>
[  +19 ms] Target web_release_bundle failed: Error: User-defined transformation of asset
           "C:\Users\username\div\My_Cool_Flutter_App\flutter_app\assets\Icons\heart_border.svg" failed.
           Transformer process terminated with non-zero exit code: 255
           Transformer package: vector_graphics_compiler
           Full command: C:\src\flutter\bin\cache\dart-sdk\bin\dart.exe run vector_graphics_compiler
           --input=C:\Users\username\AppData\Local\Temp\flutter_tools.9e394f6\heart_border.svg-transformOutput0.svg
           --output=C:\Users\username\AppData\Local\Temp\flutter_tools.9e394f6\heart_border.svg-transformOutput1.svg
           stdout:

           stderr:
           Cannot rename file to

'C:\Users\username\div\My_Cool_Flutter_App\flutter_app\.dart_tool/pub\bin\vector_graphics_compiler\vector_graphics_compiler.dart-3.4.4.sn
           apshot', path =

'C:\Users\username\div\My_Cool_Flutter_App\flutter_app\.dart_tool/pub\bin\vector_graphics_compiler\tmpb6899b1\vector_graphics_compiler.da
           rt-3.4.4.snapshot.incremental.temp' (OS Error: Access is denied.
           , errno = 5)
           PathAccessException: Cannot rename file to

'C:\Users\username\div\My_Cool_Flutter_App\flutter_app\.dart_tool/pub\bin\vector_graphics_compiler\vector_graphics_compiler.dart-3.4.4.sn
           apshot', path =

'C:\Users\username\div\My_Cool_Flutter_App\flutter_app\.dart_tool/pub\bin\vector_graphics_compiler\tmpb6899b1\vector_graphics_compiler.da
           rt-3.4.4.snapshot.incremental.temp' (OS Error: Access is denied.
           , errno = 5)

           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      copyAssets.<anonymous closure> (package:flutter_tools/src/build_system/targets/assets.dart:154:19)
           <asynchronous suspension>
           #2      Future.wait.<anonymous closure> (dart:async/future.dart:524:21)
           <asynchronous suspension>
           #3      copyAssets (package:flutter_tools/src/build_system/targets/assets.dart:126:3)
           <asynchronous suspension>
           #4      WebReleaseBundle.build (package:flutter_tools/src/build_system/targets/web.dart:450:29)
           <asynchronous suspension>
           #5      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:875:9)
           <asynchronous suspension>
           #6      Future.wait.<anonymous closure> (dart:async/future.dart:524:21)
           <asynchronous suspension>
           #7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32)
           <asynchronous suspension>
           #8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:642:16)
           <asynchronous suspension>
           #9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:92:34)
           <asynchronous suspension>
           #10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:230:5)
           <asynchronous suspension>
           #11     FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1394:27)
           <asynchronous suspension>
           #12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #14     FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:372:9)
           <asynchronous suspension>
           #15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:308:5)
           <asynchronous suspension>
           #17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
           <asynchronous suspension>
           #18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #19     main (package:flutter_tools/executable.dart:93:3)
           <asynchronous suspension>


[  +10 ms] Compiling lib\main.dart for the Web... (completed in 118.8s)
[   +1 ms] "flutter web" took 123,432ms.
[  +41 ms] Error: Failed to compile application for the Web.
</details>

Also, please note this is not a persistent error. Subsequently building the app WITHOUT any changes resolves it and the OS no longer throws a permission denied error when build tool tries to rename the vector file. It's a 50/50 chance of a build succeeding.