OpenNHP/opennhp · error

Error: fail to generating temporary file path

Error message

Error: fail to generating temporary file path: %w

What it means

When refreshing the smart data policy for a non-decrypted data object, the agent needs a temp file path (utils.GenerateTempFilePath("plaintext-*")); failure to create that path is wrapped as this error. It blocks decrypting the wrapped data key to disk before TA invocation.

Solutions

  1. Check TMPDIR/ os.TempDir() points to a writable existing directory
  2. Free disk space / fix permissions on the temp directory
  3. Inspect the wrapped error (%w) for the exact OS-level cause
Defensive patterns

Strategy: validation

Validate before calling

tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
    return fmt.Errorf("temp dir %s not usable: %v", tmp, err)
}

Try / catch

out, err := a.StartConfidentialComputing(ztdoId, ...)
if err != nil && strings.Contains(err.Error(), "temporary file path") {
    log.Fatalf("fix TMPDIR/disk space: %v", err)
}

Prevention

When it happens

Trigger: StartConfidentialComputing/AccessData path with decrypted==false where utils.GenerateTempFilePath fails — typically os.CreateTemp failing due to unwritable TMPDIR, full disk, or bad pattern.

Common situations: Read-only or missing temp directory (TMPDIR pointing to a nonexistent path); disk quota exceeded; container with no writable /tmp.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/99dda806d8a93e60. Report an issue: GitHub.

Appendix: source

Thrown at endpoints/agent/udpagent.go:1353

		DoId:                       ztdoId,
		UserId:                     a.config.UserId,
		TeePublicKey:               teeEcdh.PublicKeyBase64(),
		ConsumerEphemeralPublicKey: consumerEphemeralEcdh.PublicKeyBase64(),
	}
	serverPeer := a.GetFirstServerPeer()
	result, dagMsg := a.SendDARMsgToServer(serverPeer, darMsg)
	if result {
		a.trustedByNHPDB.Store(true) // agent has been trusted by NHP DB

		// update smart data policy refresh time
		a.smartDataPolicyRefreshTime[ztdoId] = time.Now().UnixNano()

		log.Info("[StartConfidentialComputing] Refresh smart data policy for data object which id is %s", ztdoId)

		if !decrypted {
			output, err = utils.GenerateTempFilePath("plaintext-*")
			if err != nil {
				return "", fmt.Errorf("Error: fail to generating temporary file path: %w", err)
			}

			dataPrkWrapping := ztdolib.DataPrivateKeyWrapping{}

			if err := json.Unmarshal([]byte(dagMsg.Kao.WrappedDataKey), &dataPrkWrapping); err != nil {
				log.Error("failed to unmarshal data private key wrapping: %v\n", err)
				return "", fmt.Errorf("failed to unmarshal data private key wrapping: %v", err)
			}

			providerPbk, _ := base64.StdEncoding.DecodeString(dataPrkWrapping.ProviderPublicKeyBase64)

			if dagMsg.AccessUrl == "" {
				log.Error("access url is empty, please check with data provider")
				return "", fmt.Errorf("access url is empty, please check with data provider")
			}

			var err error
			ztdoPath, err := utils.DownloadFileToTemp(dagMsg.AccessUrl, "ztdo-")

View on GitHub (pinned to 6e04ca5ff0)