bufbuild / protovalidate

Protocol Buffer Validation - Go, Java, Python, and C++ Beta Releases!
https://buf.build/bufbuild/protovalidate
Apache License 2.0
918 stars 37 forks source link

proto/buf/validate/validate.proto: does not exist #12

Closed CoolGoose closed 1 year ago

CoolGoose commented 1 year ago

Description

I am somehow making it so that I can't use the new validate beta

Steps to Reproduce

  1. Create auth.proto file in proto/auth/v1/auth.proto
syntax = "proto3";

package auth.v1;

import "buf/validate/validate.proto";
  1. My buf.gen
    version: v1
    managed:
    enabled: true
    go_package_prefix:
    default: github.com/SuppaDuppa/leprechaun/api/gen
    plugins:
    - plugin: buf.build/protocolbuffers/go
    out: gen
    opt: paths=source_relative
    - plugin: buf.build/bufbuild/connect-go
    out: gen
    opt: paths=source_relative

    buf.lock

    
    # Generated by buf. DO NOT EDIT.
    version: v1
    deps:
    - remote: buf.build
    owner: bufbuild
    repository: protovalidate
    commit: ca37dc8895db4729ac94f62f00fbd994
    digest: shake256:42c51d9091a313379dfdb0482cd86d2de412eb856721ac637bc8ff986694fd27924214440681f678c4c9dd2c24af0b4f59caf53e60d6fd1caa48c2d66d6c0425

buf.work

version: v1 directories:

version: v1
deps:
  - buf.build/bufbuild/protovalidate
breaking:
  use:
    - FILE
lint:
  use:
    - DEFAULT
  ignore:
    - buf.build/bufbuild/protovalidate

Expected Behavior

Being able to run buf generate

Actual Behavior

proto/auth/v1/auth.proto:5:8:proto/buf/validate/validate.proto: does not exist

Environment

rodaine commented 1 year ago

Hey, thanks for the report! I'm having trouble reproducing this.

Can you confirm that this is your directory structure:

buf.work.yaml
buf.gen.yaml
proto/
  buf.yaml
  buf.lock
  auth/v1/
    auth.proto

And you are executing buf generate from the same directory as the buf.gen.yaml?


This won't fix your issue, but you can also remove the lint.ignore directive from buf.yaml (dependencies aren't linted), and make sure that you add an except to managed mode so that dependencies are imported from the correct go package.

CoolGoose commented 1 year ago

Hey @rodaine thanks for the quick reply 🥂

My directory structure is actually

proto/
    auth/v1/
        auth.proto
buf.gen.yaml
buf.lock
buf.work.yaml 
buf.yaml

I did remove the lint + added the except to managed mode in buf.yml but it didn't do the trick

Moving buf.yaml + buf.lock did indeed fix it, so I apologise for the mixup. I do wonder by which luck this made it work before

rodaine commented 1 year ago

I believe the CLI gets confused here because buf.work.yaml indicates proto as a buf module directory. When buf generate runs, it consults buf.work.yaml for the modules to target, and then looks in the proto directory for a buf.yaml. Since there wasn't one, it assumes it's the default settings (without the protovalidate dependency), and as a result cannot resolve a path for buf/validate/validate.proto.