Skip to content

[Bug]: readdir wirft Fehler #1939

@ente34

Description

@ente34

I'm sure that

  • This issue is still present in the current beta version of this adapter
  • There is no other (open) issue with the same topic (use the search!)
  • This issue is not described in the adapter documentation / FAQ (read the docs!)

Script type

JavaScript

The problem

const fs = require('fs');
const util = require('util');
const my_readdir = util.promisify(fs.readdir);

const searchDir = '/tmp';

async function FindFile(dir) {
	let rc = '';
	try {
		let files = [];
		files = await my_readdir(dir);
		for (let file of files) {
			let fullpath = dir + '/' + file;
			rc = fullpath;
		}
	} catch (e) {
		console.log(e);
	} finally {
		return rc;
	}
}

function execPromise(command) {
	return new Promise(function(resolve, reject) {
		exec(command, (error, stdout, stderr) => {
			if (error) {
				//console.log(stderr);
				reject(error);
				return;
			}
			resolve(stdout.trim());
		});
	});
}

try {
	let result = FindFile(searchDir);
	//let result = await execPromise(find ${searchDir} -type f );
	log(result);
} catch (e) {
	console.error(e.message);
}

iobroker.current.log (in debug mode!)

javascript.0 2025-07-27 11:42:01.749 info script.js.Test.readdir: TypeError: Cannot read properties of undefined (reading 'ProtectFs') at readdir (/opt/iobroker/node_modules/iobroker.javascript/src/lib/protectFs.ts:625:14) at node:internal/util:438:7 at new Promise (<anonymous>) at readdir (node:internal/util:424:12) at FindFile (script.js.Test.readdir:114:23) at script.js.Test.readdir:142:18 at script.js.Test.readdir:152:3 at Script.runInContext (node:vm:149:12) at Script.runInNewContext (node:vm:154:17) at JavaScript.execute (/opt/iobroker/node_modules/iobroker.javascript/src/main.ts:2203:27)

Version of nodejs

20.19.1

Version of ioBroker js-controller

7.0.7

Version of adapter

9.0.8

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions