https://pantsbuild.org/ logo
#development
Title
# development
b

bored-art-40741

04/01/2021, 12:04 AM
So I'm hacking on a rule, and I'm now stuck at a point where I see this output ad infinitum:
Copy code
20:03:30.47 [ERROR] panic at 'called `Result::unwrap()` on an `Err` value: "Field `content` was not convertible to type alloc::vec::Vec<u8>: PyErr { ptype: <class \'TypeError\'>, pvalue: Some(\'an integer is required (got type str)\'), ptraceback: None }"', src/intrinsics.rs:354
20:03:30.47 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at <https://github.com/pantsbuild/pants/issues>.
20:03:30.47 [INFO] Filesystem changed during run: retrying `@rule(pants.backend.experimental.jvm.goals.coursier_resolve.coursier_generate_lockfile)` in 500ms...
(That's with
RUST_BACKTRACE=1
already set)
h

hundreds-father-404

04/01/2021, 12:05 AM
ctrl-c aggressively and/or use
ps aux | grep pantsd
kill -9 <pid>
b

bored-art-40741

04/01/2021, 12:06 AM
Oh I didn't have any issue killing it, I just don't know what's causing it
I'm betting it's something in this rule:
Copy code
@rule(level=LogLevel.DEBUG)
async def digest_to_file_digest(request: ExtractFileDigest) -> FileDigest:
    digest = await Get(Digest, DigestSubset(request.digest, PathGlobs([request.file_path])))
    digest_contents = await Get(DigestContents, Digest, digest)
    if len(digest_contents) == 0:
        raise Exception(f"ExtractFileDigest: '{request.file_path}' not found in {request.digest}.")
    elif len(digest_contents) > 1:
        raise Exception(
            f"ExtractFileDigest: Unexpected error: '{request.file_path}' found multiple times in {request.digest}"
        )

    file_content = digest_contents[0]
    hasher = hashlib.sha256()
    hasher.update(file_content.content)
    return FileDigest(
        fingerprint=hasher.hexdigest(), serialized_bytes_length=len(file_content.content)
    )
h

hundreds-father-404

04/01/2021, 12:07 AM
FFI error. Oh, I think you're maybe passing unicode
str
instead of
bytes
b

bored-art-40741

04/01/2021, 12:08 AM
classic
🙃 1
h

hundreds-father-404

04/01/2021, 12:08 AM
FYI this is the intrinsic rule to go from
CreateDigest -> Digest
, with a bad
FileContent
entry
b

bored-art-40741

04/01/2021, 12:09 AM
Sorry, I didn't follow that
This is a rule I wrote as a hacky workaround for https://github.com/pantsbuild/pants/issues/11806
h

hundreds-father-404

04/01/2021, 12:11 AM
Are you calling
await Get(Digest, CreateDigest)
somewhere? The Rust stacktrace is saying that the error is coming from the rule written in Rust ("an intrinsic rule") that goes from CreateDigest to Digest Specifically, that rule implemented in Rust is failing because the
CreateDigest
object has a
FileContent
value in it that has a field
content
set as unicode str, instead of
bytes
. To fix your issue, you will need to find that bad
FileContent
and encode the
content
b

bored-art-40741

04/01/2021, 12:12 AM
ah OK, that helps
h

hundreds-father-404

04/01/2021, 12:15 AM
I recommend adding this to `FileContent`:
Copy code
def __post_init__(self):
  if isinstance(self.content, str):
     raise ValueError(self)
This will cause Python to error on the problematic FileContent using Python's dataclass mechanism.
b

bored-art-40741

04/01/2021, 12:15 AM
ahhh,
json.dumps
doesn't return
bytes
Of course, why would a serializer return you something appropriate for the wire? Because Python, that's why
h

hundreds-father-404

04/01/2021, 12:19 AM
Prob changed between Py2 and Py3 also hehe